Delphi Dynamic Configuration ODBC Data source--sql Server version

Source: Internet
Author: User
Tags dsn odbc

(excerpt from) http://jxlearnew.blog.163.com/blog/static/549786592007102451431413/

Here is a method of using Delphi to achieve dynamic registration, I hope to help you.
Here we directly use the SQLConfigDataSource function provided in ODBCCP32.DLL, which can be declared in Delphi as follows:
//Configure ODBC data source, Success returns true
function SQLConfigDataSource (
Hwndparent:integer;
Frequest:longint;
Lpszdriverstring:string;
lpszattributes:string
): longbool; stdcall; external "" ODBCCP32. DLL "";
Parameter Description:
1, hwndparent: Parent window Handle, the dialog box does not appear when specified as 0, otherwise the standard ODBC Configuration dialog box
2, frequest: Command request is used to indicate the function you want to complete, and its value can be:
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;
3, Lpszdriverstring: driver name, which is the name of the driver that is displayed in the ODBC settings, such as SQL Server and Microsoft Access Driver (*.mdb)
4, Lpszattributes : Some properties of this DSN can have multiple items, separated by semicolons (;) delimited by

After declaring the above functions first in Delphi, the following steps are as follows:
1. Declaring constants:
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;
2. Put a button in the form and write in its event
Procedure Tform1.button1click (Sender:tobject);
Begin
SQLConfigDataSource (0,
Odbc_add_sys_dsn,//~ replaced with handle is manual configuration
' SQL Server ',//database type
' Dsn=house ' #0 +//Data source Name
' Server= (local) ' #0 +//sql Server server name
' Database= house Sales database ' #0 +//database name
' description= dynamic configuration ODBC ' #0//description
);
End
When you click Button1, the data source house information has been successfully written to the registry
The above method has been tested in Delphi 7.0, but before applying this method, make sure that the Microsoft SQL Server2000 database system is properly installed on your machine, and that database = home sales databases are present, otherwise an unknown error may occur.

Delphi Dynamic Configuration ODBC Data source--sql Server version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.