Export (0) Print
Expand All

Configuring Data Controls to Use Universal Data Link (.udl) Files

Visual Studio .NET 2003

Using the Data Link Properties dialog box, you can store a connection string to a particular database provider in a universal data link (.udl) file. An ADO Data Control can then use this .udl file when opening a connection to this DataSource for a DataGrid, DataCombo, or DataList control in your Visual Studio .NET project or form.

To configure Data Control to use a .udl file to connect to a DataSource

  1. Create a universal data link (.udl) file.
  2. Use the Data Link Properties dialog box to store a connection string in this .udl file.
  3. Add an ADO Data Control to your solution or project.
  4. In the Properties window for your ADO Data Control, select the ConnectionString property and enter the name of the .udl file with the desired connection string. You can also set this property in your code.

    In the following example, the ConnectionString property of a control named cnPubs is set to a universal data link file named Pubs.udl, whose absolute path is given:

    cnPubs.ConnectionString = "File Name=C:\Path\To\Pubs.udl;" 

    You also can give a relative path:

    cnPubs.ConnectionString = "File Name=Data\Pubs.udl;" 

    If you give a relative path, the specified universal data link file will be located beginning from the directory where the application is installed.

  5. Add a DataGrid, DataCombo, or DataList control to your project or form.
  6. In the Properties window, set the DataSource property of that DataGrid, DataCombo, or DataList control to the name of the ADO Data Control just configured.

Whenever your project or form requests data, this DataGrid, DataCombo, or DataList control will call its DataSource, the ADO Data Control, which in turn will use the ConnectionString provided by the Universal Data Link (.udl) file to open the desired data connection.

For more information, see ADO Data-Bound Controls, Databinding with ActiveX Controls in Visual C++, and HOWTO: How to Bind the Datagrid Control to the ADO Data Control on a Web Page.

ADO.NET Technology

Instead of creating data connections with ADO that remain open continuously until you close them, you might consider the disconnected data architecture of ADO.NET technology. ADO.NET makes it possible for you to connect programmatically to a data source just long enough to download and cache the XML data sets you require. You can then work offline with the data retrieved, without having to keep a network connection open. For more information, see Overview of ADO.NET, Introduction to Data Access with ADO.NET, and Accessing Data with ADO.NET.

See Also

Creating and Configuring Universal Data Link (.udl) Files | Data Controls | Data Access Technologies | Information on Data Link Properties and OLE DB Providers | Displaying Data Sources in Server Explorer | Adding New Data Connections in Server Explorer | Adding Items from Server Explorer

© 2015 Microsoft