我想使用VBscript连接到databsae。按照几个站点的建议安装了oracle客户端和odbc驱动程序。从http://qtpromania.blogspot.in/2013/05/how-to-connect-to-oracle-database-using.html复制了vbscript。我安装了oracle 11g快递版。 想先用本地数据库运行代码,然后尝试连接服务器端数据库。但是当我执行我的vbscript时,我无法连接到数据库。这是我缺少的东西。请建议。
'首先尝试使用本地数据库。后来我想连接服务器端'数据库 HOST =" localhost" PORT =" 1521" SID =" XE" USER =" system" PASSWORD =" system"
Srvname="Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST="& HOST &")(PORT="& PORT &"))" & _
"(CONNECT_DATA=(SID="& SID &"))); uid="& USER &";pwd="& PASSWORD &";"
Set Rec = CreateObject("ADODB.Recordset")
Set conn=Createobject("ADODB.Connection")
MsgBox "Before"
MsgBox Srvname
'Cannot get past this point.Its like I cannot connect to the path
' I have installed oracle client recently.
conn.open Srvname
If conn.State = "1" Then 'Check connection
MsgBox "Connected to DB"
Else
MsgBox "NOT connected to DB"
End If
SQLSec="select Age from Persons where Name like 'A%'" 'SQL statement
Rec.open SQLSec,conn
Age=Rec.fields("AGE") 'AGE is the name of the column
Rec.Close
MsgBox Age
答案 0 :(得分:0)
尝试使用connecttring:
Srvname="Driver={Microsoft ODBC for Oracle}; Server=""" & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST="& HOST &")(PORT="& PORT &"))" & _
"(CONNECT_DATA=(SID="& SID &")))""; uid="& USER &";pwd="& PASSWORD &";"
您安装了哪个Oracle客户端 - 64位还是32位?
检查是否安装了ODBC驱动程序“Microsoft ODBC for Oracle”。在我的机器上它只存在32位,但默认情况下VBscript在64位环境中运行。这不匹配。
为了检查32位ODBC驱动程序运行c:\Windows\SysWOW64\odbcad32.exe
对于64位ODBC驱动程序运行c:\Windows\System32\odbcad32.exe