Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating flexible database Connections

Posted on 2004-04-19
5
Medium Priority
?
305 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:jupiterz
5 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 10862929
>>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.
0
 

Author Comment

by:jupiterz
ID: 10862957
Exactly that is what I want to do, but need code how to create this INI or XML file from VB.
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 10863091
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.
0
 
LVL 9

Accepted Solution

by:
dancebert earned 2000 total points
ID: 10863419
Saving passwords in plain text is not a good idea.  I store them as an encrypted string.  The program reads the encrypted string, decripts it into a plain text connection string, then connects to the database.
0
 
LVL 3

Expert Comment

by:redfordb
ID: 10867175
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question