ADO ConnectionString

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

ConnectionStr.lpr Pascal (666 Bytes) 21.12.2013 18:25
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.

Kontakt

Udo Schmal
Udo Schmal

Udo Schmal
Softwareentwickler
Ellerndiek 26
24837 Schleswig
Schleswig-Holstein
Germany




+49 4621 9785538
+49 1575 0663676
+49 4621 9785539
SMS
WhatsApp

Google Maps Profile
Instagram Profile
vCard 2.1, vCard 3.0, vCard 4.0

Service Infos

CMS Info

Product Name:
UDOs Webserver
Version:
0.5.1.71
Description:
All in one Webserver
Copyright:
Udo Schmal
Compilation:
Tue, 26. Mar 2024 07:33:29

Development Info

Compiler:
Free Pascal FPC 3.3.1
compiled for:
OS:Linux, CPU:x86_64

System Info

OS:
Ubuntu 22.04.4 LTS (Jammy Jellyfish)

Hardware Info

Model:
Hewlett-Packard HP Pavilion dm4 Notebook PC
CPU Name:
Intel(R) Core(TM) i5-2430M CPU @ 2.40GHz
CPU Type:
x86_64, 1 physical CPU(s), 2 Core(s), 4 logical CPU(s),  MHz