无法使用 ADODB 连接到 oracle11g 数据库

unable to connect to oracle11g db using ADODB

我正在尝试使用 ADODB 验证 oracle 数据库中的数据。我安装了 Oracle Client x64 位并正确配置了环境变量。出于某种原因,下面的代码抛出 automation error 这对缩小问题的范围不是很有帮助。

PS: 我也试过安装 32 位版本的 oracle 客户端。

Sub test()
    myHost = ""
    Database_Name = ""
    myUsername = ""
    myPassword = ""
    serviceID = ""
    myPort = ""

    strConnectionString = "Driver={Oracle in OraClient11g_home1}; " & _
                            "SERVER=(DESCRIPTION=" & _
                            "(ADDRESS=(PROTOCOL=TCP)" & _
                            "(HOST=" & myHost & ")(PORT=" & myPort & "))" & _
                            "(CONNECT_DATA=(SERVICE_NAME=" & serviceID & "))); uid=" & myUsername & ";pwd=" & myPassword & ";"

    Debug.Print strConnectionString
    'Instantiate the Connection object and open a database connection.
    Set cnn = CreateObject("ADODB.Connection")
    cnn.Open strConnectionString
    'Above line throws error 


End Sub

错误信息

*

Microsoft Visual Basic for Applications

Run-time error '-2147217843 (80040e4d)': Automation error OK Help

*

想到寻求专家支持。

我无法在 OraClient11g_home1 驱动程序中使用 Oracle。所以我安装了 32 位 Microsoft ODBC for Oracle 并完成了工作。

Set objCon = CreateObject("ADODB.Connection")
Set objRec = CreateObject("ADODB.RecordSet")
Dim fieldName, fieldValue
Dim host_name: host_name = ""
Dim service_name: service_name = ""
Dim user_name : user_name = ""
Dim pass : pass = ""
Dim strSQL : strSQL = ""
Dim data_array
data_array = Array("","","")

conStr = "Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" & host_name & ")(PORT=1525))(CONNECT_DATA=(SERVICE_NAME=" & service_name & "))); Uid=" & user_name & ";Pwd=" & pass &";"
objCon.Open conStr      

objRec.Open strSQL, objCon

Set objFields = objRec.Fields
Do Until objRec.EOF
    For intLoop = 0 To (objFields.Count - 1)
        fieldName = objFields.Item(intLoop).Name
        fieldValue = objFields.Item(intLoop).Value          
        If Cstr(fieldValue) = Cstr(data_arr(intLoop)) Then
            Debug.print "Check value of " & fieldName &  " Value of " & fieldName & " in DB " & fieldValue & " is same as application " & data_arr(intLoop)
        Else
            Debug.print "Check value of " & fieldName &  " Value of " & fieldName & " in DB " & fieldValue & " is not same as application " & data_arr(intLoop)
        End If
    Next
    objRec.MoveNext
Loop

objRec.Close
objCon.Close