vbamysql⾃动化错误_在Excel中运⾏VBA脚本时出现⾃动化错
误
在Excel 2007中运⾏VBA代码时出现⾃动化错误。我尝试连接到远程SQL Server数据库并将数据从Excel加载到SQL Server。在Excel 中运⾏VBA脚本时出现⾃动化错误
mysql下载odbc失败我得到的错误是,
“运⾏时错误 '-2147217843(80040E4D)':⾃动化错误”。
我检出了MSDN⽹站,它提⽰这可能是由于与sqloledb提供程序相关的错误,并且缓解此问题的⼀种⽅法是使⽤ODBC。那么我改变了连接字符串以反映ODBC提供者和相关参数,我仍然得到相同的错误。
下⾯是ODBC的代码提供者:
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stSQL As String
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnStart As Range
Public Sub loadData()
'This was set up using Microsoft ActiveX Data Components version 6.0.
'Create ADODB connection object, open connection and construct the connection string object.
Set cnt = New ADODB.Connection
cnt.ConnectionString = _
"Driver={SQL Server}; Server=onlineSQLServer2010.foo; Database=fooDB Uid=logonalready;Pwd='helpmeOB1';"
cnt.Open
On Error GoTo ErrorHandler
'Open Excel and run query to export data to SQL Server.
strSQL = "SELECT * INTO SalesOrders FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0', & _
"'Data Source=C:\Database.xlsx; Extended Properties=Excel 12.0')...[SalesOrders$]"
cnt.Execute (strSQL)
'Error handling.
ErrorExit:
'Reclaim memory from the connection objects
Set rst = Nothing
Set cnt = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ErrorExit
'clean up and reclaim memory resources.
cnt.Close
If CBool(cnt.State And adStateOpen) Then
Set rst = Nothing
Set cnt = Nothing
End If
End Sub
2010-03-27
brohjoe
+0
在哪⼀⾏发⽣错误?另外,你的sql服务器密码是否有单引号? –
2010-03-27 04:35:18
+0
代码在连接字符串之后的'cnt.open()处死亡。要回答你的密码问题,我确实有单引号。 –2010-03-27 05:45:30
+0
你不需要数据库名称和⽤户名之间的分号吗? 另外,你的Sub的最后5⾏永远不会被执⾏。 –2010-03-27 16:00:29
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论