Solved

Creating flexible database Connections

Posted on 2004-04-19
5
295 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

762 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

12 Experts available now in Live!

Get 1:1 Help Now