简体   繁体   中英

MS Access to SQL Server connection

I'm using MS Access as my database, my hosting is not supporting this, and I need to know how to convert MS Access to SQL Server connection string?

This my code of data connection:

'--------------- ole parameters -------------------
Dim olecommand As Data.OleDb.OleDbCommand
Dim oledataadaptor As Data.OleDb.OleDbDataAdapter
Dim odbcDataSet As System.Data.DataSet

Sub populate_dataset_Access_accdb_test(ByRef ds As DataSet, ByVal sql As String)
    Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
    olecommand = New OleDb.OleDbCommand
    olecommand.CommandText = sql
    odbcDataSet = New System.Data.DataSet
    olecommand.Connection = myDataConnection

    myDataConnection.Open()
    oledataadaptor = New OleDbDataAdapter(sql, myDataConnection)
    oledataadaptor.Fill(ds)

    myDataConnection.Close()

End Sub

Sub insert_dataset_Access_accdb_test(ByVal sql As String)
    Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
    olecommand = New OleDb.OleDbCommand
    olecommand.CommandText = sql
    odbcDataSet = New System.Data.DataSet
    olecommand.Connection = myDataConnection

    myDataConnection.Open()
    olecommand = New OleDbCommand(sql, myDataConnection)
    olecommand.ExecuteNonQuery()


    myDataConnection.Close()

End Sub

Sub cr_ds(ByRef ds As DataSet, ByVal sql As String, ByVal tablename As String)
    Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
    olecommand = New OleDb.OleDbCommand
    olecommand.CommandText = sql
    odbcDataSet = New System.Data.DataSet
    olecommand.Connection = myDataConnection

    myDataConnection.Open()
    oledataadaptor = New OleDbDataAdapter(sql, myDataConnection)
    oledataadaptor.Fill(ds, tablename)

    myDataConnection.Close()
End Sub

Thank you in advance

You can't just change an Access connection string to an SQL connection string and have things work. You would have to port your data From Access to the SQL Server.

I think it is more likely that when you deploy your Access database to the server, the path is different. You probably need to modify the config file to point to to where the Access file is on the server.

As Steve Wellens pointed out, you miss some basic things here. Since your host does not support your data source type (MS Access), changing your connection string is not enough . You have to use a data store supported by your hosting service. I suppose that Microsoft SQL Server is one of them, but you have to verify it by contacting your hosting service administration support.

Regarding the transfer of data between MS Access and MS SQL Server, you could get some guidance here .

Regarding the MS SQL Server connection strings, you could get some help from this post but you have to verify the availability of the MS SQL Server database with your hosting service.

Hope I helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM