无法使用VB脚本连接到Oracle数据库

时间:2013-03-12 08:00:35

标签: oracle vbscript connection odbc adodb

嗨请帮我解决以下问题。我使用下面的VB代码将文本文件上传到我的oracle数据库。当我运行我的脚本时,我收到错误消息“Class not defined ADODB”

Set Obj_DBConn = New ADODB.Connection
Set cat = New ADOX.Catalog



Obj_DBConn.ConnectionString ="Driver={Microsoft ODBC for Oracle}; " & _
                             "CONNECTSTRING=(DESCRIPTION=" & _
                             "(ADDRESS=(PROTOCOL=TCP)" & _
                             "(HOST=##test##)(PORT=##test##))" & _
                             "(CONNECT_DATA=(SERVICE_NAME=##test##))); " & _
                             "uid=test;pwd=test;"


Obj_DBConn.Open Database_Path


Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")




Set f = Nothing

Set f = fso.OpenTextFile("C:\Documents and Settings\test.txt", ForReading, True)

For i = 1 To 10000

v_Line_String = f.ReadLine


v_Output_Each_part = Split(v_Line_String,";",-1,1)

v_Col_A = v_Output_Each_part(0)
v_Col_B = v_Output_Each_part(1)
v_Col_C = v_Output_Each_part(2)



Obj_DBConn.Execute "INSERT INTO  test_me (ID_Q, NAME, ROLLNO) VALUES ('"       & v_Output_Each_part(0) & "','" & v_Output_Each_part(1) & "','" & v_Output_Each_part(2) & "')"



Next

请提供您的见解提前致谢

1 个答案:

答案 0 :(得分:1)

Set Obj_DBConn = New ADODB.Connection

是VBA,而不是VBScript。使用

Set Obj_DBConn = CreateObject("ADODB.Connection")

让这一行通过解释器。

如果您承诺删除邪恶的“On Error Resume Next”,您可以从here获得更多灵感。

<强>更新

如果你谷歌搜索类似“80004005 odbc oracle”的东西,你会发现this trouble shooter有详细的分步说明来处理连接问题。下一站可能应该是connectionstrings.com