ActiveX Data Objects (ADO)provides similar functionality in the form of a Data Link file (*.udl).
Create a Data Link File
- Right-click the directory where you want to store the file, point to New, and then click Microsoft Data Link. A new file appears in the directory with the name New Microsoft Data Link.udl. Rename the file to Pubs.udl. Note: If using Windows 2000, right-click where you want to store the file, point to New, and then click Text Document. Change the txt filename extension to
- Double-click the newly created file to set the properties for the Data Link. You see the following tabs:Provider | Connection | Advanced | All
- The Provider tab allows you to specify the provider (the default is Microsoft OLE-DB provider for ODBC drivers). Use the Default provider, and then click Next.
- The Connection tab allows you to specify either the data source name that is designated in the ODBC Administrator, or allows you to provide the connection string.
You can provide information with one of the following two methods:
- Use a predefined DSN name for the connection (it has all the information to connect to the Data source)
- Build a connection string, or use a known connection string.
- To complete the settings, click OK . To learn more about Data Link files, see the Msdasc.hlp Help file, that you can find in the following directory: C:\Program Files\Common Files\System\ole db.
- Open a text editor, such as Notepad, and then drag the
DataLink icon to a blank document. You see the connect string that the data link represents. You can use this connect string in your code.
Use a Data Link File in Code with an ADO ConnectionUsing a Data Link file for an ADO connection is fairly simple. The following is the syntax, using an absolute path:
cnPubs.ConnectionString = "File Name=C:\Path\To\Pubs.UDL;"
รหัสบทความ: 189680 - การตรวจสอบครั้งสุดท้าย: 17 ธ.ค. 2008 - ฉบับแก้ไข: 1