Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection string syntax for Classic ADO / ODBC / Oracle 10g EZConnect

I'm trying to connect various VBA projects to an Oracle 10g back end using ADO (2.8) and no TNS. After various attempts, we've decided that the simplest series of steps for a clean installation include:

  1. Set up an Oracle Instant Client
  2. Install the accompanying ODBC driver
  3. (Test the connection using EZCONNECT via SQL Plus)
  4. (Test the connection by creating a Windows DSN)

Everything up to here works fine. Problem is, I cannot figure out the syntax to tell ADO to use the instant client ODBC driver, which appears in my ODBC driver list as "Oracle in MyTest" (no quotes). Using the MSFT ODBC driver with EZConnect as this post suggests does not work any better than it did prior to setting up the instant client (which is to say, not at all). But this post seems to suggest it's possible, without stating exactly how, and connectionstrings.com only tells you what the Data Source portion of the string looks like, i.e. SomeUser/SomePassword@AServer:PortNumber/InstanceName

Short version: What is the exact syntax of a classic ADO connection string referencing an instant client ODBC driver?

Thanks in advance for your help. Took me a stupid long time to get going with SO...

like image 235
downwitch Avatar asked Aug 03 '10 15:08

downwitch


People also ask

What is the connection string for Oracle database?

Oracle allows database administrators to connect to Oracle Database with either SYSDBA or SYSOPER privileges. Data Source=myOracle;User Id=myUsername;Password=myPassword;DBA Privilege=SYSDBA; SYSOPER is also valid for the DBA Privilege attribute.


1 Answers

Similar to 'user1206604's answer - I set up an ODBC connection using ODBC Data Source Administrator (for example's sake we'll name it 'DEMO') and connect like this:

Dim conn As New adodb.Connection
Set conn = New adodb.Connection

connStr = "Provider=OraOLEDB.Oracle;Data Source=DEMO;User Id=yourUserID;Password=yourPassword;"
conn.Open connStr

Dim api As New adodb.Recordset
Set api = New adodb.Recordset

yourQueryString = "SELECT foo FROM bar"
api.Open yourQueryString, conn, adOpenDynamic, adLockReadOnly 
'adjust above setting as needed

while not api.EOF
  'do interesting stuff here
wend

'clean up resources
api.Close
Set api = Nothing

conn.Close
Set conn = Nothing

The ODBC data source administrator is found (on my machine) in start menu > Programs > Oracle - oraClient10g > Configuration and Migration Tools > Microsoft ODBC Administrator and looks like this:

ODBC Data Source Administrator

like image 100
Richard Avatar answered Oct 18 '22 20:10

Richard