Login | Register   
RSS Feed
Download our iPhone app
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 29, 2005



Application Security Testing: An Integral Part of DevOps

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
                       "(ADDRESS_LIST=" & _
                       "(ADDRESS=(PROTOCOL=TCP)" & _
                       "(HOST=prodtst1.sdd.hp.com)" & _
                       "(PORT=1521)))" & _
                       "(CONNECT_DATA=(SID=prod_tst)" & _
    cnxDB.ConnectionString = "Provider=OraOLEDB.Oracle;" & _
                       "Data Source=" & TNS_INFO & ";" & _
                       "user id=cressman;" & _
    Debug.Print cnxDB.ConnectionString
Bill Cressman
Comment and Contribute






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



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date