我是excel 2007的初学者。我正在尝试建立与oracle数据库10G的连接并从中提取数据。我收到“运行时错误:' - 2147467259(80004005)': 自动化错误未指定错误“。此代码适用于我的大四。请帮忙!!
Sub build_database_connection()
Dim cn As ADODB.Connection
Set cn= New ADODB.Connection
servername = example.com
UserName = example
pass = example
cn_cdcp.Open "Provider=MSDAORA.1;Data Source=" & servername & ";User ID=" & UserName & "Password=" & pass & ";"
End Sub
答案 0 :(得分:0)
乍一看,上面的代码存在一些问题,我不确定它是否只是复制问题,但无论如何我都去了。
Sub build_database_connection()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
servername = "example.com" '<~~ the ".." defines a string
UserName = "example" '<~~ the ".." defines a string
pass = "example" '<~~ the ".." defines a string
'cn_cdcp doesn't exist use cn instead
'correct connection string should be
'"Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;"
'<~~ you missed a ;
cn.Open "Provider=MSDAORA.1;Data Source=" & servername & _
";User ID=" & UserName & ";Password=" & pass & ";"
End Sub
上面说的我觉得你的问题出在连接字符串中。有关详情,请参阅Connection Strings。
你的Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;