Mega Code Archive

 
Categories / Delphi / Strings
 

Two easiest ways to create valid connection strings

Title: Two easiest ways to create valid connection strings. Question: Smebody said it can be a pain creating connection string to complicated ADO datasources... :-) Absolutely not! Answer: I use these two functions when it's necessary to allow user to connect to different Data Sources. They can be also included into project temporarily when testing or preparing application to use some data from DB. {===========================================================================} { uses imported ADO type library or ADOInt unit } function MakeConnectionString(): string; var v: OleVariant; Conn: _Connection; begin Conn := CoConnection.Create; v := CreateOleObject('DataLinks') as IDispatch; v.PromptEdit(Conn); Result := Conn.ConnectionString; Conn := nil; end; {===========================================================================} { uses ADODB unit } function ProduceConnectionString(): string; begin Result := PromptDataSource(Forms.Application.MainForm.Handle, ''); end; WBR, Igor