dcsimg
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
Thanks for your registration, follow us on our social networks to keep up-to-date