Solved

Creating flexible database Connections

Posted on 2004-04-19
5
296 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 49

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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now