Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB
Expertise: Advanced
Mar 29, 2005

Connecting to Oracle without Configuring the tnsnames.ora File

Have you ever wanted to connect to a database without dealing with Oracle's annoying reliance on the tnsnames.ora file?

The trick is to put the tnsnames information into the ODBC connection string directly, using the Data Source=... option.

The following (untested) code is VB, but the concept should work in any language that supports ODBC:


    Dim TNS_INFO As String
    Dim cnxDB As New ADODB.Connection
    
    TNS_INFO = "(DESCRIPTION=" & _
                       "(ADDRESS_LIST=" & _
                       "(ADDRESS=(PROTOCOL=TCP)" & _
                       "(HOST=prodtst1.sdd.hp.com)" & _
                       "(PORT=1521)))" & _
                       "(CONNECT_DATA=(SID=prod_tst)" & _
                       "(SERVER=DEDICATED)))"
    
    cnxDB.ConnectionString = "Provider=OraOLEDB.Oracle;" & _
                       "Data Source=" & TNS_INFO & ";" & _
                       "user id=cressman;" & _
                       "password=mean2me"
    Debug.Print cnxDB.ConnectionString
    cnxDB.Open
Bill Cressman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap