Get/Set ADO Connection string at Runtime or from File

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?

Thanks

ST3VO
ST3VOAsked:
Who is Participating?
 
JohnjcesCommented:
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);
begin
 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;
 ADOTable1.Open;
 TGOBadgeIni.Free;
end;

The ini file has this in it...

Path\Name=\\HonDah-ServerB\DataBase\TGOBadges.mdb

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

Hope this helped.

John

0
 
Tomas Helgi JohannssonCommented:
  Hi!

Here is one example : http://www.swissdelphicenter.ch/torry/showcode.php?id=551
and here is another example : http://www.swissdelphicenter.ch/torry/showcode.php?id=2271
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.

Regards,
   Tomas Helgi
0
 
JohnjcesCommented:
Did any of this help you?
0
 
ST3VOAuthor Commented:
Yes it did! Sorry about me delay! Thanks a lot!!!!

ST3VO
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.