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; ODBC_ADD_SYS_DSN = 4; ODBC_CONFIG_SYS_DSN = 5; ODBC_REMOVE_SYS_DSN = 6; 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; stdcall; external '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));
if ret <> 1 then raise (Exception.Create('Fehler beim Erstellen der Datenquelle')); End; |