Solved

Creating flexible database Connections

Posted on 2004-04-19
5
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 52

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 52

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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 17 hours left to enroll

636 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