Get/Set ADO Connection string at Runtime or from File

Posted on 2007-09-28
Last Modified: 2010-04-05
Hi all,

I've got an application which connects to an access DB via ADO.
I need to be able to 1. Setup the connection string at runtime or 2. pick the connection string from a file.

The reason why I want to do this is because I would like to have different connections available....for example: Access, SQL Server etc...

Is there away to do this please?


Question by:ST3VO
    LVL 24

    Expert Comment

    by:Tomas Helgi Johannsson

    Here is one example :
    and here is another example :
    I personally use similar method like the first one to connect to Access DB where
    I have some text instead of the path  to the db in the connection string and on appl startup I
    replace that text with the actual path to the db.
    Hope this helps.

       Tomas Helgi
    LVL 18

    Accepted Solution

    I us the following when usina ADO and an Access db and retrieve my main setting, the mdb location and name, from an INI file. This is in the form's OnCreate event.

    procedure TFTGOBadges.FormCreate(Sender: TObject);
     TGOBadgeIni := TIniFile.Create(ExtractFileDir(ParamStr(0)) + '\TGOBadges.def');
     ConnStrB := TGOBadgeIni.ReadString('MDBFile', 'Path\Name', ExtractFileDir(ParamStr(0)) + '\TGOBadges.mdb');
     ConnStrA := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
     ConnStrC := ';Persist Security Info=False';
     ADOConnection1.ConnectionString := ConnStrA + ConnStrB + ConnStrC;
     ADOConnection1.Connected := True;

    The ini file has this in it...


    so the path and file is of course \\HonDah-ServerB\DataBase\TGOBadges.mdb

    Hope this helped.


    LVL 18

    Expert Comment

    Did any of this help you?

    Author Comment

    Yes it did! Sorry about me delay! Thanks a lot!!!!


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now