2004. augusztus 20., péntek
Create an ODBC datasource for an Access database
Problem/Question/Abstract:
How to create an ODBC datasource for an Access database
Answer:
unit odbcsetup;
{Written By Aaron Miles 2002
Creates ODBC for Access Database}
interface
uses
sysutils, windows;
procedure CreateDSN(Name, Database: string);
procedure RemoveDSN(Name: string);
implementation
const
ODBC_ADD_DSN = 1; {Add data source}
ODBC_CONFIG_DSN = 2; {Configure (edit) data}
ODBC_REMOVE_DSN = 3; {Remove data source}
ODBC_ADD_SYS_DSN = 4; {Add a system DSN}
ODBC_CONFIG_SYS_DSN = 5; {Configure a system DSN}
ODBC_REMOVE_SYS_DSN = 6; {Remove a system DSN}
ODBC_REMOVE_DEFAULT_DSN = 7; {Remove the default DSN}
function SQLConfigDataSource(hwndParent: HWND; fRequest: WORD; lpszDriver: LPCSTR;
lpszAttributes: LPCSTR): BOOL; stdcall; external 'ODBCCP32.DLL';
procedure CreateDSN(Name, Database: string);
begin
SQLConfigDataSource(0, ODBC_ADD_DSN, 'Microsoft Access Driver (*.mdb)', PChar('DSN =
'+Name+ #0 + ' Driver = ODBCJT32.DLL '#0 + ' DBQ = '+Database+ #0 +
'DefaultDir=' + ExtractFilePath(Database) + #0 + 'Description=Auto Setup
Aaron Miles '#0 + ' FIL = MS Access '#0 + ' UID = Admin'#0));
end;
procedure RemoveDSN(Name: string);
begin
SQLConfigDataSource(0, ODBC_REMOVE_DSN, 'Microsoft Access Driver (*.mdb)',
PChar('DSN=' + Name + #0));
end;
end.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése