Link to home
Start Free TrialLog in
Avatar of jupiterz
jupiterz

asked on

Creating flexible database Connections

I am looking out for best way of creating database connections from VB to Oracle.

Using the following connection strings to the same database using differnt providers how can I make it flexible that users can log on to different datasources like "Development" to "Test" to "Production" so that my program automatically know what datasource they are connecting to.  

    With Conn
            .ConnectionString = "Provider=OraOLEDB.Oracle;" & _
                                        "User ID=abc;" & _
                                        "Password=xyz;" & _
                                        "Data Source=development;" & _
                                        "Persist Security Info=False"
            .CursorLocation = adUseClient
            .Open
    End With

        With m_conData
           .ConnectionString = "Provider=MSDAORA.1;" & _
                                        "User ID=abc;" & _
                                        "Password=xyz;" & _
                                        "Data Source=development;" & _
                                        "Persist Security Info=False"
            .CursorLocation = adUseClient
            .Open
        End With
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>how can I make it flexible that users can log on to different datasources like "Development" to "Test" to "Production" so that my program automatically know what datasource they are connecting to.
Is that mean the user cannot log on to a database to determine whether they are connecting to a "Test" or a "Production" Oracle server (Because the application also donno where to connect..). Since then, what i can thinking off is set the connectionString as a value and save it into a Local File. The Local File can be as a INI File, an XML file, any user-defined file format, or even Registry. Where the user info of UserID, Password (optional, or can be compare/authenticate while connecting to Oracle Server that determine by ConnectServerType), and ConnectServerType is saved in the Local File.
Avatar of jupiterz
jupiterz

ASKER

Exactly that is what I want to do, but need code how to create this INI or XML file from VB.
Some useful examples here on how to read/write values in a INI file:

Using INI Files to Save Application Data - The Basics
http://vbnet.mvps.org/code/file/pprofilebasic.htm

.INI File Reader and Writer
http://www.freevbcode.com/ShowCode.Asp?ID=4786

Read And Write From INI File Demo
http://www.freevbcode.com/ShowCode.Asp?ID=4578

Simple INI Read/Write Module
http://www.freevbcode.com/ShowCode.Asp?ID=2035

The format of your INI file should something like:

[User1]
UserName=user1
ConnectionString=Provider=OraOLEDB.Oracle;User ID=abc;Password=xyz;Data Source=development;Persist Security Info=False

[User2]
UserName=user2
ConnectionString=Provider=MSDAORA.1;User ID=abc;Password=xyz;Data Source=development;Persist Security Info=False

[User<N..>]
UserName=user<N...>
ConnectionString=Provider=OraOLEDB.Oracle;User ID=abc;Password=xyz;Data Source=development;Persist Security Info=False

* Where you need to read the available section in a Loop, stop the loop when the section is Not found.

For XML, you need to use the XML Object Library to parse the XML file. Let us know if you need XML examples.
ASKER CERTIFIED SOLUTION
Avatar of dancebert
dancebert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The method ryansys recommends is the way I do it, show a login screen with a combobox filled with the database names, a user name and password textboxes. Then just use the replace function to replace the abc of the connection string with the supplied username and the xyz with the supplied password. Then you dont need to store the passwords outside of the database.