Autor Beitrag
jjturbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Di 06.09.11 07:56 
Moin Forum,

wie kann ich eine ODBC Datenquelle zur Laufzeit erstellen?
Ich meine hier schon mal etwas darüber gelesen zu haben, finde es aber nicht wieder.

Gruß Oliver

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Di 06.09.11 08:54 
Moin,

SQLConfigDataSource ist das Stichwort. Der Rest ist Fleiß:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
uses SysUtils;

Const ODBC_ADD_DSN = 1//Add user data source
      ODBC_ADD_SYS_DSN = 4//Add data source
      ODBC_CONFIG_SYS_DSN = 5//Configure (edit) data source
      ODBC_REMOVE_SYS_DSN = 6//Remove data source
      ODBC_FIREBIRDDRIVERNAME = 'Firebird/InterBase(r) driver';
      
type TodbcType = (otUser, otSystem);

Procedure BuildDSN(ot : TodbcType; sDSNName, sPath, sUser, sPassword : String);

implementation

Function SQLConfigDataSource( hwndParent, fRequest : Integer;
                              lpszDriver, lpszAttributes : AnsiString): Integer;
                              stdcallexternal 'ODBCCP32.DLL' name 'SQLConfigDataSource';

Procedure BuildDSN(ot : TodbcType; sDSNName, sPath, sUser, sPassword : String);
Var ret : Integer;
    Attributes : String;
    sDriver : String;
    iODBCType : Integer;
Begin

  sDriver := ODBC_FIREBIRDDRIVERNAME + Chr(0);
  Attributes := 'DSN=' + sDSNName + Chr(0);
  Attributes := Attributes + 'Uid=' + sUser + Chr(0) + 'pwd=' + sPassword + Chr(0);
  Attributes := Attributes + 'DBNAME=' + sPath + Chr(0);
  Attributes := Attributes + 'CLIENT=' + extractFilePath(ParamStr(0)) + 'fbClient.dll' + chr(0);
  Attributes := Attributes + 'CharacterSet=UTF8' + chr(0);

  if ot = otUser then
    iODBCType := ODBC_ADD_DSN
  else
    iODBCType := ODBC_ADD_SYS_DSN;

  ret := SQLConfigDataSource(0, iODBCType, AnsiString(sDriver), AnsiString(Attributes));

  //'ret is equal to 1 on success and 0 if there is an error
  if ret <> 1 then
    raise (Exception.Create('Fehler beim Erstellen der Datenquelle'));
End;

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
jjturbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Di 06.09.11 10:46 
Ok, danke, das klappt :)

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...