|
|
| The basic process is to link into ODBC and create a "datasource" that points to a database (eg *.mdb) so that any program can link into this. This method standardizes database connections and complicates your life. |
|
Step 1: Drop in a reference to the DLL SQLConfigDataSource Function function SQLConfigDataSource(hwndParent: THandle; fRequest: Integer; lpszDriver, lpszArgs, lpszMsg: PChar; cbMsgMax: Word; var pcbMsgOut: Word): Boolean; stdcall; and/or function SQLConfigDataSource(hwndParent: THandle; fRequest: Integer; lpszDriver, lpszArgs, lpszMsg: PChar; cbMsgMax: Word; var pcbMsgOut: Word): Boolean; external 'ODBCCP32.DLL';
Step 2:
Function CreateDataSource(AName, FileName, Description: String): Boolean;
Args: PChar; MsgOut: PChar; OutLen: Word;
StrCopy(Cs, 'Microsoft Access Driver (*.mdb)'); GetMem(Args, 255); StrPCopy(Args, 'CREATE_V2DB=None; DSN=' + AName + '; Description=' + Description + '; DBQ=' + FileName); GetMem(MsgOut, 255); OutLen := 0; If SQLConfigDataSource(Application.Handle, 1, Cs, Args, MsgOut, 255, OutLen) then Result := True else Result := False; FreeMem(Cs, 255); FreeMem(Args, 255); FreeMem(MsgOut, 255); |
|
Notes: This function will create a Dialog box that will harass the user to press OK to the changes. This is normal since the ODBC people anticipated that many users would want to redirect database connections. |