[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

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
0
ST3VO
Asked:
ST3VO
  • 2
1 Solution
 
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:
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
 
JohnjcesCommented:
Did any of this help you?
0
 
ST3VOAuthor Commented:
Yes it did! Sorry about me delay! Thanks a lot!!!!

ST3VO
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now