2016-07-29 44 views
0

怎麼會看的連接字符串到Oracle數據庫,如果我有這樣的參數:Vb的conncetion串到Oracle數據庫

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 

糾正我請!

+0

你的問題還不清楚。你有錯誤嗎?什麼是您的數據庫的TNSNAME和您的Microsoft Oracle驅動程序的版本是什麼?無論如何,答案可能是[這裏](https://www.connectionstrings.com/oracle/) –

回答

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 

不過,我不知道甲骨文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驅動程序(雖然微軟的ODBC驅動程序是deprecated)使用這一個:ADO ConnectionStings

+0

非常感謝!) –