【问题标题】:runtime error: automation error while trying to connect to oracle database via Excel macro运行时错误:尝试通过 Excel 宏连接到 oracle 数据库时出现自动化错误
【发布时间】:2013-04-29 17:59:43
【问题描述】:

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

【问题讨论】:

  • cn_cdcp在哪里声明?
  • 几个问题; cn_cdcp 应该是 cn 吗?而example.com"example.com"

标签: excel oracle10g database-connection excel-2007 vba


【解决方案1】:

乍一看,上面的代码有一些问题,我不确定它是否只是问题的复制,但无论如何我都走了。

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;

【讨论】:

    猜你喜欢
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 2017-08-20
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多