How will look connection string to Oracle db if I have such parameters:
HOST = host
PORT = 1531
SERVICE_NAME = service_name
User: USER_ADMIN
pass: USER_ADMIN
Now I have connection string like this:
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
Correct me please!
Your connection string is wrong, you cannot use Provider=OraOLEDB.Oracle and Driver={Microsoft ODBC for Oracle} at the same time.
In case you like to use the Oracle OLE DB provider try this:
Set oConn = CreateObject("ADODB.Connection")
oConn.provider = "OraOLEDB.Oracle"
DB = host & ":" & port & "/" & SERVICE_NAME
oConn.Open "Data Source=DB", User, pass
which should be equivalent to:
Set oConn = CreateObject("ADODB.Connection")
DB = host & ":" & port & "/" & SERVICE_NAME
oConn.Open "Provider=OraOLEDB.Oracle;Data Source=DB;User Id=" & User & ";Password=" & pass
However, I do not know whether Oracle OLE DB supports Easy Connect Naming Method (EZ), I never used it. In case it does not support EZ try this one instead:
DB = "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=" & host & ")(PORT=" & port & "))(CONNECT_DATA=(SERVICE_NAME=" & SERVICE_NAME & ")))"
Actually such definition should be written in tnsnames.ora file, e.g.
DB_TNS.your.domain =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=host)(PORT=1531))
(CONNECT_DATA=
(SERVICE_NAME=service_name)
(SERVER=server)
(INSTANCE_NAME=instance_name)
)
)
Then you can simply use oConn.Open "Data Source=DB_TNS", User, pass
In case you prefer to use the ODBC driver (although the ODBC driver from Microsoft is deprecated) use this one: ADO ConnectionStings
Related
This may seem to be a pretty basic issue but I am not able to find any solution for this. I have to admit that I have very little experience with databases. I looked at THIS question but it didn't help me much.
Issue:
Whenever I modify my query to fetch data of type CLOB from the database, I get the error "Unspecified Error". In the below code, I have written the query strQuery = "select CDATA from WR2_USR.router_xml_data where EVENT_ID= '987787454'". The column CDATA(of datatype CLOB) contains an Long XML which I need to fetch and store in a variable for further use. Is there any way to achieve that?
Code:
Option Explicit
Dim objCon, objRs, strCon, strQuery, i, strServer, strUid, strPwd
set objCon = CreateObject("adodb.connection")
set objRs = CreateObject("adodb.recordset")
strServer = "" 'Contains the correct Server information
strUid = "" 'Contains the user name
strPwd = "" 'Contains the password
strCon = "Driver={Microsoft ODBC for Oracle};SERVER="&strServer&";uid="&strUid&";pwd="&strPwd &";"
strQuery = "select CDATA from WR2_USR.router_xml_data where EVENT_ID= '987787454'"
objCon.open strCon
if objCon.state=1 then
objRs.open strQuery, objCon '<--- GETTING ERROR HERE
while (not objRs.eof)
msgbox objRs.fields.count
for i=0 to objRs.fields.count-1 step 1
msgbox cstr(objRs.fields.item(i).value)
next
objRs.movenext
Wend
end if
set objCon = Nothing
set objRs = Nothing
Error:
Column Details:
NOTE: If I change my query to fetch some other Column's data(not of CLOB datatype), the code runs fine.
ODBC Driver for Oracle from Microsoft is deprecated for ages:
Oracle 7.3x is supported fully; Oracle8 has limited support. The ODBC Driver for Oracle does not support any of the new Oracle8 data types — Unicode data types, BLOBs, CLOBs, and so on — nor does it support Oracle's new Relational Object Model.
Use the ODBC driver or OLE-DB Provider from Oracle, you can download from Oracle Data Access Components (ODAC) for Windows Downloads
Then the connection string has to look similar to this:
' ODBC Driver from Oracle
strCon = "Driver={Oracle in OraClient11g_home1};DBQ=" & strServer & ";Pwd=" & strPwd & ";Uid=" & strUid
' OLE DB Provider from Oracle
strCon = "Provider=OraOLEDB.Oracle;Data Source=" & strServer & ";Password=" & strPwd & ";User ID=" & strUid
I'm using this connection string pattern with ADODB
Set oConn = New ADODB.Connection
oConn.ConnectionString = "User ID=USERNAME;Password=PW;Data Source=xxxxxxx.db.yyyy.com:port;Provider=OraOLEDB.Oracle; "
oConn.ConnectionTimeout = 30
oConn.Open
rs.CursorType = adOpenForwardOnly
and when I open the connection I'll get a run time error
ORA-12504: TNS:listener wa not given the SERVICE_NAME in CONNECT_DATA
I have also tried using this connection string
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"DBQ=" & inputHost & ";UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;DB=" & inputHost & ";" & _
"DefaultIsolationLevel=READUNCOMMITTED"
and I get the run time error
[Microsoft][ODBC Driver Manager] Data source name not found an no default driver specified
I think Data Source=xxxxxxx.db.yyyy.com:port is the problem. You should provide the TNS alias as defined in file tnsnames.ora instead of "ServerName.Domain:Port".
I do not know if OLEDB provider supports Easy Connect naming method. Did you specify like NAMES.DIRECTORY_PATH=(tnsnames, ezconnect) in your sqlnet.ora file?
I'm trying to connect to a Oracle DB and i believe the version is 12c, I'm able to connect to the same DB using a client (SQL Developer), but having issues while trying to connect using VBscript which I would like to use as part of my application.
Here is the error message --
**Exception: OraOLEDB - ORA-01017: invalid username/password; logon denied**
Here is my script that I'm using to connect --
Option Explicit
On Error Resume Next
'Dim strSQLQuery: strSQLQuery = "SELECT sysdate FROM dual"
Dim strDBDesc: strDBDesc = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = XXX)(PORT = XXX))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XXXX)))"
Dim strUserID: strUserID = "user"
Dim strPassword: strPassword = "pass"
Dim ADODBConnection: Set ADODBConnection = CreateObject("ADODB.Connection")
Dim strConnection
strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & strDBDesc & _
";User ID=" & strUserID & ";Password=" & strPassword & ";"
ADODBConnection.Open strConnection
If Err <> 0 Then
WScript.Echo "An error occurred in Opening Connection: " & Err.Number & " " & Err.Description & " " & Err.Source
End If
Set ADODBConnection = Nothing
Is the password simple or with special character? use an escape sequence or quotes if with special characters.
Based on below use "ADODBConnection.ConnectionString = strConnection" in the above snippet and then open the connection.
Place break point and see what is being passed as a connection string to the driver.
Refer: https://docs.oracle.com/cd/E47955_01/win.121/e18594/using.htm
All,
i was able to connect successfully after i have download and installed the latest copy of Oracle ODAC from their website.
here are additional details - hope this helps others having a similar issue
https://blogs.msdn.microsoft.com/dbrowne/2013/10/02/creating-a-linked-server-for-oracle-in-64bit-sql-server/
I can't seem to get my connection string correct.
Dim conn, rs
Set conn= createobject("adodb.connection")
set rs = createobject("adodb.recordset")
conn.Open "Provider=Sybase.ASEOLEDBProvider;Server Name = xxx.xxx.xxx.xxx,yyyy;User Id=user;Password=pwd;Database=mydatabase;"
rs.open "Select * from blah", conn
I keep getting an error stating, "Provider cannot be found. It may not be properly installed."
I know the provider is installed because I use the same computer for coding up C# applications that connect to Sybase 16 successfully all the time. Does anyone know the correct connection string for QTP/UFT?
I figured it out.
Dim conn, rs
Set conn= createobject("adodb.connection")
set rs = createobject("adodb.recordset")
conn.Open "Driver={Adaptive Server Enterprise}; Server=xxx.xxx.xxx.xxx; port=yyyy; uid=user; pwd=pwd; db=mydatabase;"
rs.open "Select * from blah", conn
Using this you'll be able to use QTP/UFT and connect to a sybase 16 database - so long as you have have the Sybase Adaptive Server Enterprise drivers installed on your system. It's a proprietary database and to my knowledge you'll have to either purchase drivers directly from Sybase or from a thrid party. If you're running Sybase 16 at your company you more than likely have the ASE drivers - ask around.
There is way to connect if it is in windows 7 Function
ConnectionTest()
DB_CONNECT_STRING = "Provider=OraOLEDB.Oracle; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" & myHostName & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & myServiceNameOrSID & "))); User ID=" & myUsername & ";Password=" & myPassword & ";"
Set myConn = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
myConn.Open DB_CONNECT_STRING
objRecordSet.Open myQuery, myConn
Wscript.Echo objRecordSet.fields.item(1) & " " & objRecordSet.fields.item(2)
myConn.Close
End function
Call ConnectionTest()
if there is problem in mapping adodb driver need to invoke the exe file before running in windows 64 bit
(Tearing my hair out, been doing this a million times for decades and now it doesn't work!) I have a simple VB6 program, connecting to SQL 2008 Express locally on the host machine. I can connect to the database using the same credentials in SQL Server Management Studio Express. However, when I run this code, I get the following error:
Run-time error '3706':
Method 'Open' of object '_Connection' failed
Dim DBConn As ADODB.Connection
Set DBConn = New ADODB.Connection
Dim ConnString As String
txtServer.Text = "R19DEV\SQLEXPRESS"
txtCatalog.Text = "MyDatabase"
txtUser.Text = "MyUser"
txtPassword.Text = "MyPassword"
ConnString = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=" & _
txtCatalog.Text & ";Data Source=" & txtServer.Text & ";User ID=" & txtUser.Text & _
";Password=" & txtPassword.Text
Debug.Print ConnString
DBConn.Open ConnString
Here's the connection string:
Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=R19DEV\SQLEXPRESS;User ID=MyUser;Password=MyPassword
OK, I'm not sure why this worked. I changed the connection provider from SQLOLEDB.1 to SQLOLEDB, and that fixed it.