An vielen Stellen wird in meinen Code-Schnipseln über einen ConnectionString die Verbindung zur Datenbank aufgebaut, aber wie kommt man zu diesem ConnectionString? Natürlich kann man im Internet suchen oder einfach die von mir generierten nutzen oder man schreibt sich ein kleines Progrämmchen!
Dafür braucht wir die Importe der Type Librarys "Microsoft ActiveX Data Objects 2.x-Objektbibliothek" und "OLE DB Service Component 1.0-Typbibliothek" und das Package LazActiveX.
Import ADODB : Microsoft ActiveX Data Objects 2.x-Objektbibliothek
C:\Program Files\Common Files\System\ado\msado15.dll adodb 6 1 tlb.pas (189,84 kByte) 30.12.2018 21:29
Import MSDASC : OLE DB Service Component 1.0-Typbibliothek
C:\Program Files\Common Files\System\Ole DB\oledb32.dll msdasc 1 0 tlb.pas (18,68 kByte) 30.12.2018 21:29
program ConnectionStr;
{$APPTYPE CONSOLE}
{$mode objfpc}{$H+}
uses
Interfaces, // used packages: LazActiveX
adodb_6_1_tlb, // Microsoft ActiveX Data Objects 2.x-Objektbibliothek
msdasc_1_0_tlb; // OLE DB Service Component 1.0-Typbibliothek
function getConnectionString: Widestring;
var
cn: _Connection;
dl: DataLinks;
begin
result := '';
cn := CoConnection.Create;
dl := CoDataLinks.Create;
dl.hwnd:= 0;
try
cn := Connection(dl.PromptNew);
if Assigned(cn) then
result := cn.ConnectionString;
finally
dl := nil;
cn := nil;
end;
end;
begin
WriteLn(getConnectionString());
ReadLn;
end.