从VS 2017连接到访问数据库时出错

从VS 2017连接到访问数据库时出错

问题描述:

我在连接到访问数据库时遇到问题,要从访问数据库中的SQL上传一些数据。此过程之前正在运行,但我们已迁移到新服务器,并且该过程不再有效。

I am having an issue connecting to an access database to upload some data from SQL in the access database. This process was working before but we have migrated to a new server and the process is no longer working.

这是我的代码:

       Dim g_objCn As New ADODB.Connection
       Dim g_strConnectionString As String = "C:\database\data.accdb"
       Dim connsql = New SqlConnection

        connsql.ConnectionString = "integrated security=SSPI;data source=sqlserver;" &
                                    "persist security info=False;initial catalog=MainTables;MultipleActiveResultSets=true;"
        Try
            connsql.Open()
            g_objCn.Provider = "Microsoft.ACE.OLEDB.16.0"
            g_objCn.Properties("Data Source").Value = g_strConnectionString
            g_objCn.Open()
            g_objCn.Execute("INSERT INTO [C:\database\data.accdb].tblData (id, FacN, LName,FName)" &
                            "SELECT id, FacN, LName,FName " &
            "FROM [tblData] IN '' [ODBC;Driver={SQL Server};Server=sqlserver;Database=MainTables;Trusted_Connection=yes]")

我在g_objCn行上收到以下错误.Provider =" Microsoft.Ace.oledb.16.0"。我检查了新服务器,那个库就在那里(aceoledb.dll)。所以我不确定我错过了什么。

I am getting the error below on the line g_objCn.Provider = "Microsoft.Ace.oledb.16.0". I have checked the new server and that library is there (aceoledb.dll). So I am not sure what I am missing.

消息说g_objCn未打开。您需要添加代码以捕获错误,并在出现错误时显示相关消息和其他数据。您应该在使用之前检查g_objCn是否打开。
The message is saying that g_objCn is not open. You need to add code to catch errors and to show relevant messages and other data when there is an error. You should check to see if g_objCn is open before using it.