Vb conncetion字符串到Oracle DB

时间:2016-07-29 08:01:11

标签: oracle vbscript

如果我有这样的参数,如何查看连接字符串到Oracle db:

HOST = host  
PORT = 1531
SERVICE_NAME = service_name
User: USER_ADMIN
pass: USER_ADMIN

现在我有这样的连接字符串:

set oConn =  CreateObject("ADODB.Connection") 
 oConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=host/orcl;Persist Security Info=True;User ID=user;Password=password;Unicode=True;Driver={Microsoft ODBC for Oracle};"
oConn.Open

请纠正我!

1 个答案:

答案 0 :(得分:1)

您的连接字符串错误,您无法同时使用Provider=OraOLEDB.OracleDriver={Microsoft ODBC for Oracle}

如果您想使用Oracle OLE DB提供程序,请尝试以下操作:

Set oConn = CreateObject("ADODB.Connection")
oConn.provider = "OraOLEDB.Oracle"
DB = host & ":" & port & "/" & SERVICE_NAME
oConn.Open "Data Source=DB", User, pass

应该相当于:

Set oConn = CreateObject("ADODB.Connection")
DB = host & ":" & port & "/" & SERVICE_NAME
oConn.Open "Provider=OraOLEDB.Oracle;Data Source=DB;User Id=" & User & ";Password=" & pass

但是,我不知道Oracle OLE DB是否支持Easy Connect Naming Method(EZ),我从未使用它。如果它不支持EZ,请尝试使用此代码:

DB = "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=" & host & ")(PORT=" & port & "))(CONNECT_DATA=(SERVICE_NAME=" & SERVICE_NAME & ")))"

实际上,这样的定义应该写在tnsnames.ora文件中,例如

DB_TNS.your.domain = 
  (DESCRIPTION= 
    (ADDRESS=(PROTOCOL=tcp)(HOST=host)(PORT=1531))
    (CONNECT_DATA=
      (SERVICE_NAME=service_name)
      (SERVER=server)
      (INSTANCE_NAME=instance_name)
    )
  )

然后您只需使用oConn.Open "Data Source=DB_TNS", User, pass

即可

如果您更喜欢使用ODBC驱动程序(尽管Microsoft的ODBC驱动程序是deprecated),请使用以下代码:ADO ConnectionStings