Delphi universal database connection file (*. udl)

Source: Internet
Author: User

1. Right-click --- New --- Text Document and rename it connection. udl.

2. Double-click connection. udl and follow the prompts to configure the database. select local or remote database. After the configuration is complete, exit.

3. Use the Delphi control tadoconnection connection code:

The oncreate event of form1 is as follows:

Try
Adoc. Connected: = false;
Adoc. connectionstring: = 'file name = '+ extractfilepath (paramstr (0) +'/pymee. udl ';
Adoc. provider: = extractfilepath (paramstr (0) + '/pymee. udl ';
Adoc. Connected: = true;
Except
Showmessage ('Connection failed, please reconfigure pymee. udl file ');
Exit;
End;

4. If you want to distribute applications to the LAN for use, the database server does not change. You can simply copy the application without configuring the connection. udl file. When a database server with different names is installed in another LAN, right-click the connection. udl file in notepad and you will see:

[Oledb]
; Everything after this line is an ole db initstring
Provider = sqloledb.1; persist Security info = false; user id = sa; initial catalog = jbdatabase0; Data Source = jiabao9/jiabao9

The above lines of files. This is the code automatically generated after the connection. udl file is created and the database is configured. My default logon user is SA, the password is blank, the database is bdatabase0, And the LAN Database Server is named jiabao9/jiabao9 (IP: 192.168.0.9). You can configure it according to your actual environment.

5. For different LAN Database servers, you only need to modify and configure the connection. udl connection file. You do not need to modify the Delphi code, which is very convenient.

6. troubleshooting: when running the application, an error message "invalid authorization description" appears, because we have created a connection. udl connection, now you only need to delete the connectionstring value of the tadoconnection attribute of the Delphi control as null, which is the string value of the static Connection database. Therefore, after deleting the connectionstring value, re-compile it.

 

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.