1

我是 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
4

1 回答 1

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

在说上面我认为你的问题是在连接字符串。有关更多信息,请参阅连接字符串

你的应该是Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;

于 2013-04-29T09:59:43.563 回答