Share via


Data Link API Overview

The Data Link API exposes a user interface that you can implement in your applications to create and manage connections to OLE DB data stores.

Because the Data Link API is included with OLE DB as a core component, the user interface is always available to your application users if ADO or OLE DB is properly installed on their system.

Before you can access data from OLE DB, you must provide specific connection information such as the following:

  • The type of data that you want to access.

  • The server on which the data resides.

  • The database in which the data is stored.

For example, to connect to a Microsoft? SQL Server? database, you must specify the OLE DB provider for SQL Server, a server name, and a database name.

You can call the Data Link API to build a string version of this connection information, which you can save and reuse in your applications. This string version is referred to as a connection string. The user interface object that prompts users to build the connection string is referred to as the Data Link Properties dialog box. The information specified in a connection string may vary depending on the OLE DB provider that is specified.

Using the Data Link Properties dialog box, your end users can build connection strings directly within your application. Once created, a connection string can either:

  • be saved within the application itself.

  • be saved as a separate file with the .udl extension. This file is referred to as a Microsoft Data Link file.

The following table compares the differences between these two saving options.

Saving a connection string with the application data

Saving a connection string as a Data Link (.udl) file

Connection string is saved and stored with the application.

Connection string is saved as a .udl file, enabling users to save and modify it from their system.

Connection string is part of the application and is therefore automatically redistributed with the application.

The .udl file must be included as a separate file when you redistribute your application.

If the connection information changes, the connection string must be modified from within your application.

Users can modify the .udl file at any time if the connection information changes.

Users can also build connection strings using the Data Link Properties dialog box. On Microsoft Windows? 95 systems, a Data Link icon was created in the Windows Control Panel when Data Access components were installed. On Windows 98 and Windows NT systems where Data Access components were installed, right-clicking on the Desktop allowed the user to select New and then Microsoft Data Link to create a .udl file.

On computers running the Windows 2000 operating system, you can access the Data Link Properties dialog box by following these steps:

  1. Open Windows Explorer.

  2. Select the folder in which you want to save the .udl file. Right-click in the right, or results pane, point to New, and then click Text Document.

  3. On the Tools menu, click Folder Options. On the View tab, clear the Hide file extensions for known file types check box and then click OK.

  4. Right-click on the text file you created in step 2, and then click Rename. Type the new file name using a .udl file extension. Press Enter.

  5. A warning may appear, explaining that changing file extensions may cause files to become unusable. Disregard this warning.

Store .udl files anywhere on your system or network.

Note

You can manually build a connection string as long as it conforms to the syntax rules. For more information about the format of a connection string, see Connection String Syntax.

The first two lines of a .udl file must have exactly the following contents in order to work properly:

[oledb]
; Everything after this line is an OLE DB initstring

After these first two lines, the remainder of the file contains the connection string in the same format used when opening a database from code. The following example uses the OLE DB provider for Microsoft SQL Server to open the Northwind database.

[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind

The Data Link API includes the following dialog boxes:

  • Data Link Properties

  • Select Data Link File

Note

To get help information about the Data Link interface, press F1 while viewing an active dialog box.

The Data Link Properties dialog box is typically used either to edit an existing connection string or to build a new connection string. This tabbed dialog box exposes all of the properties that the selected OLE DB provider supports. For example, the Advanced tab includes default settings that the user can modify as necessary. The Connection tab is provider-specific.

If, instead of storing a connection string directly within your application, you want your application to reference a .udl file, you can prompt users with the Select Data Link File dialog box. This allows the user to select from existing .udl files as well as to create new ones.

For example, if your application supports .udl files, a user could create a .udl file that points to the user's Customer database. Then, by using the Select Data Link File dialog box, the user could specify this .udl file to access the Customer database.

Referencing a .udl file is beneficial to users if a database is upgraded to a different server or is modified. In either case, the user simply edits the connection string within the .udl file with the updated information, and the application that uses this file will instantly reflect the changes.

The Select Data Link File dialog box returns the selected .udl file to the application.

Properties Set by the Connecting Application

The properties in the following list will not be persisted to the .udl file. They are generally set by the connecting application at run time. Although these can be set manually, they could be easily overwritten by the connecting application.

  • DBPROP_INIT_OLEDBSERVICES

  • DBPROP_INIT_HWND

  • DBPROP_INIT_PROMPT

  • DBPROP_INIT_ASYNCH

  • DBPROP_INIT_TIMEOUT

  • DBPROP_INIT_LCID

See Also

Reference

Referencing a Connection String in Your Application

Connection String Syntax