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.