
Building and Saving Connection Strings Using the Data Link Properties Dialog Box
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:
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:
-
Open Windows Explorer.
-
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.
-
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.
-
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.
-
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. |
Microsoft Data Link File Format
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 |