Export SQL Database to Access - ASP.NET

Is there a way to export data (not necessarily a schema) to an access database via asp.net?

There are no office components installed on the server, and the process must be executed through a web page (for example, excel export).

+3
source share
2 answers

You must do this programmatically.

  • Open source table
  • Create a new AccessDB using ADO Extensions (as shown above)
  • Create a table in AccessDB by reading the source schema (CREATE TABLE X ...)
  • Iterate thought the source table inserts records into the Access table

Note: the code from http://www.freevbcode.com/ShowCode.asp?ID=5797 is posted here if the link ceases to exist in the future

    'select References from the Project Menu, choose the COM tab, 
    'and add a reference to Microsoft ADO Ext. 2.7 for DDL and Security

    Public Function CreateAccessDatabase( ByVal DatabaseFullPath As String) As Boolean
        Dim bAns As Boolean
        Dim cat As New ADOX.Catalog()
        Try


         'Make sure the folder
         'provided in the path exists. If file name w/o path 
         'is  specified,  the database will be created in your
         'application folder.

            Dim sCreateString As String
            sCreateString = _
              "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
               DatabaseFullPath
            cat.Create(sCreateString)

            bAns = True

        Catch Excep As System.Runtime.InteropServices.COMException
            bAns = False
            'do whatever else you need to do here, log, 
            'msgbox etc.
        Finally
            cat = Nothing
        End Try
        Return bAns
    End Function


    DEMO
    ====


    '      If CreateAccessDatabase("F:\test.mdb") = True Then
    '           MsgBox("Database Created")
    '      Else
    '           MsgBox("Database Creation Failed")
    '      End If
+2
+1

Source: https://habr.com/ru/post/1698854/


All Articles