Configuration method for ODBC data sources when publishing procedures

zhaozj2021-02-08  275

Digital to the ODBC Data Source, 2002.4.8 Method 1: Modify Registry

When making an installer, use the installer's production tool to modify the registry, complete the configuration of the ODBC data source, the ODBC can be used in the HKEY_LOCAL_MACHINE / SOFTWARE / ODBCAL_MACHINS / Software / ODBC / ODBCINST.INI of the system registry, ODBC's System SYSTEM DSN under the HKEY_LOCAL_MACHINE / SOFTWARE / ODBCAL_MACHINE / Software / ODBC / ODBC.INI of the system registry, ODBC's User DSN's hkey_current_user / software / odbc / odbc.ini in the system registry, you can open the registration table and see it! Method 2 : Program setting method, can use its own program to complete ODBC configuration, a simple method is to implement a function provided in odbccp32.dll, this function can be declared in Delphi:

// configuring ODBC data source, successfully returns True function SQLConfigDataSource (hwndParent: Integer; fRequest: LongInt; lpszDriverString: string; lpszAttributes: string): LongBool; stdcall; external 'ODBCCP32.DLL';

Parameter Description: HWndParent: Parent window handle 1; ODBC_CONFIG_DSN = 2; ODBC_REMOVE_DSN = 3; ODBC_ADD_SYS_DSN = 4; ODBC_CONFIG_SYS_DSN = 5; ODBC_REMOVE_SYS_DSN = 6; lpszDriverString: driver name, driver name is displayed in the ODBC settings, such as Microsoft Access driver (* .mdb) lpszAttributes: Some properties of this DSN include multiple items, and the sequel (;) separation is as follows:

const ODBC_ADD_DSN = 1; ODBC_CONFIG_DSN = 2; ODBC_REMOVE_DSN = 3; ODBC_ADD_SYS_DSN = 4; ODBC_CONFIG_SYS_DSN = 5; ODBC_REMOVE_SYS_DSN = 6; into a Button in the Form, the write procedure TForm1.Button1Click (Sender: TObject) in its event; begin SQLConfigDataSource (0, ODBC_ADD_SYS_DSN, 'Microsoft Access Driver (* .mdb)', 'DSN = MyAccessDB; DBQ = C: /MyDB/MyDB.MDB; DefaultDir = C: / MyDB; FIL = MS Access; MaxBufferSize = 2048; PageTimeout = 5; Description = My database '); END; click Button1 to open the ODBC setup program of the control panel after clicking Button1, you can see the DSN named myaccessdb

You can also see the new joined HKEY_LOCAL_MACHINE / SOFTWARE / ODBCAL_MACHINI / SOFTWARE / ODBCAL_MACHINE / SOFTWARE / ODBCAL_MACHINI / SOFTWARE / ODBCAL_MACHINI / SOFTWARE / ODBCAL_MACHINI / SOFTWARE / ODBC / ODBC.INI / MyAccessDB key, and other parameters specified in the function are stored.

If instead procedure TForm1.Button1Click (Sender: TObject); begin SQLConfigDataSource (Handle, ODBC_ADD_SYS_DSN, 'Microsoft Access Driver (* .mdb)', 'DSN = MyAccessDB; DBQ = C: /MyDB/MyDB.MDB; DefaultDir = C : / Mydb; fil = ms access; maxbuffersize = 2048; pagetimeout = 5; description = my database ');

After clicking Button1, a set form of a standard Access data source will pop up, as shown below:

转载请注明原文地址:https://www.9cbs.com/read-3401.html

New Post(0)