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) 22.03.2013 10:20 (189,84 KB)

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) 01.12.2013 13:50 (18,68 KB)

ConnectionStr.lpr Pascal (666 bytes) 21.12.2013 17: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.

Autor: , veröffentlicht: , letzte Änderung:

Kontakt

Copyright / License of sources

Copyright (c) 2007-2017, Udo Schmal <udo.schmal@t-online.de>

Permission to use, copy, modify, and/or distribute the software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Service Infos

CMS Info
UDOs Webserver

0.3.1.24

All in one Webserver

Udo Schmal

Sa, 21 Okt 2017 00:30:10
Development Info
Lazarus LCL 1.9.0.0

Free Pascal FPC 3.1.1

OS:Win64, CPU:x86_64
Hardware Info
Precision WorkStation T3500

Intel(R) Xeon(R) CPU W3530 @ 2.80GHz

x86_64, 1 physical CPU(s), 4 Core(s), 8 logical CPU(s), 2800 MHz