Three methods for connecting to the database using Delphi

Source: Internet
Author: User
Tags odbc connection

References:
1. Use BDE
If you use BDE, the speed will be faster (relative to ODBC). The connection requires Dao support. The specific method is as follows:
BDE --> Configuration --> drivers --> native --> msaccess --> dll32
Set the value of dll32 to idda1_2.dll;
Then you can directly reference it. For example:
BDE --> databases --> New --> select msaccess from database driver name --> Database Name
Set the database name value to your own database.

2. Use ODBC
Open the control panel, double-click the "32-bit ODBC" icon, and the "ODBC data source Manager" dialog box appears. Then, click the "add" button. The "create data source" dialog box appears, select Microsoft Access driver and click Finish. The "ODBC Microsoft Access 97 installation" dialog box appears. Enter the database alias in the "Data Source Name" text box, enter the corresponding description in the "Description" text box, and then click "select" to select the system database, click OK.

3. Through ado
In the design phase, create the tadoconnection and TADODataSet controls, set the connection attribute of the TADODataSet control to tadoconnection, and set the connectionstring attribute of the tadoconnection control to connect.
Specific Method:
Click connectionstring dialog box, select build..., click next, and then you can connect according to your actual situation!

Experience: MDAC (including ODBC) and related connection libraries are required for connection through that method, and Dao support is required for connection through BDE (ODBC is not required ), however, you can select this option when installing the office.
The last note is what everyone cares about: How to cancel the Password dialog box?
Whether using BDE or ODBC, you must create a tdatabase control to cancel the password, set aliasname, and set the loginprompt attribute to true, but the parameters of the Params attribute are different.
If you use ODBC connection, Set
User name = yourname
Password = yourpass
If you use BDE for connection, Set
Password = yourpass
Cannot be confused. Otherwise, an error occurs!

As for other issues in the actual application process, note that the procedures of the database cannot be identified through the BDE connection!

(1) first, create a new data source, for example, dsn_access, and configure parameters. You should do that, so I won't talk about it;
(2) then, place a tdatabase control on the form and double-click it. In the pop-up window, select the data source from the alias name drop-down list box, write the same name in the name drop-down list box on the left (it is best to set another name), click ults on the right, and set the check box login pormpt to false. Press OK to exit.
(3) set the databasename attribute of the table control to the name of the data source you just created (it should be consistent with the name in the dialog box just now ). Set the tablename attribute of the table.

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.