Microsoft KB Archive/300261

= How To Create an ADO Connection from a Data Link File in Data Access Components =

Article ID: 300261

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7

-



This article was previously published under Q300261





IN THIS TASK
SUMMARY
 * Requirements
 * How to Create a Data Link File
 * Steps to Build a Connection String
 * Steps to Using Your UDL File
 * Additional Information
 * Troubleshooting

REFERENCES



SUMMARY
Microsoft Data Links provide an easy way to create or validate a Microsoft ActiveX Data Objects (ADO) connection string that uses an ODBC driver or an OLE DB Provider to connect to a given data source. This article describes how to set up and use this Universal Data Link (UDL) Wizard.

back to the top

Requirements
The following items describe the recommended hardware, software, network infrastructure, skills and knowledge, and service packs you will need:  MDAC 2.5 or later as well as any one of the following operating systems:

Microsoft Windows 95, Windows 98, Windows NT 4.0, or Windows 2000

NOTE: MDAC Data Links drivers are available after you have installed Microsoft Visual Basic 6.0, Microsoft Data Access SDK 2.x, or Microsoft Data Access Components (MDAC) 2.x run-time components. MDAC 2.5 is installed by default with Windows 2000. You can access Data Links from the Visual Basic 6.0 Data Environment or from the Microsoft Windows 95, Windows 98, Windows NT 4.0, or Windows 2000 shell, as outlined in the following steps.

 Familiarity with Data Access Technology and Syntax (ADO)

back to the top

How to Create a Data Link File

 * 1) Right-click anywhere on the Windows 2000 desktop, point to New, and then click text document. A new file is created by default (New Text Document.txt).
 * 2) Right-click the new text document that you just created and select rename, and then change the name and extension of the file to DataLink.udl and press ENTER.

If you do not see the file extension, open Windows Explorer. From the Tools menu, click Folder Options. On the View tab, clear the hide file types for known file types checkbox, and then click OK.NOTES:


 * 1) * A warning might appear, explaining that changing file extensions could cause files to become unusable. Disregard this warning and click OK.
 * 2) * You can store the Datalink.udl file anywhere on your system or network.
 * 3) Double-click the Datalink.udl file or right-click it and then click Properties. This opens the Data Link Properties dialog box. You are now ready to create your data connection.NOTE: The file's icon now looks like a computer with a datasheet in the background. If you still see the Microsoft Notepad text file icon, ensure that the file extension is showing correctly by following step 2. Then rename if necessary.

back to the top

Steps to Build a Connection String
 Double-click Datalink.udl and use the Wizard as follows:  Click the Provider tab. From the Providers menu, select the appropriate OLE DB or ODBC provider (you may only have OLE DB providers on your computer):  select Microsoft Jet 4.0 OLE DB Provider for Microsoft Access 2000 or 2002 databases</li> select Microsoft Jet 3.51 OLE DB Provider for Access 97 databases</li> select OLEDB Provider for SQL for Microsoft SQL Server databases</li> select OLEDB Provider for Oracle for Oracle databases</li></ul> </li> Click Next to proceed to the Connections tab.</li></ol> </li> With the Properties dialog box displayed, use the Connection tab to create a connection to a datasource: <ol style="list-style-type: lower-alpha;"> Type your database name or browse to the database you want to connect to.</li> If you have created an account to use for Internet connections to the database, enter those credentials. Otherwise, you can use the default settings. (To use the default settings, enter Admin as the user name, and then select the Blank Password checkbox). If you do not want to use the default credentials, follow the steps under &quot;Additional Information,&quot; later in this article, to configure the System database.</li></ol>

NOTE: You can optionally use the Advanced tab to set access permissions and All tab to set specific data type behavior available to either an ODBC or OLE DB data source.

</li> Click test your connection to ensure that the connection will be successful.</li> After you have successfully completed and tested your connection, click OK to save your new data link and close the Wizard.</li></ol>

back to the top

Steps to Using Your UDL File
From the .udl file, the connection string can be copied and used in an application that supports MDAC technology. <ol> Right-click the Datalink.udl file and rename it as Datalink.txt. Click Yes in the warning dialog box that appears.</li>  Double-click Datalink.txt, and a statement similar to the following appears: [oledb] ; Everything after this line is an OLE DB initstring Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My.mdb;User ID=;Password=; </li></ol>

The following line is the connection string from My.txt: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My.mdb;User ID=;Password=; The following sample code illustrates how this connection string can be incorporated into an ASP page: Set objCXN = Server.CreateObject(&quot;ADODB.Connection&quot;) strCXN = &quot;Microsoft.Jet.OLEDB.4.0;Data Source=C:\My.mdb;User ID=;Password=;&quot; objCXN.Open strCXN .     .      .   objCXN.Close Set objCXN = Nothing back to the top

Additional Information
If you are specifying an Access database username and password, use the following steps to specify the path and the password to access the System.mdw file.

In the UDL Wizard: <ol> Click the All tab.</li> Select the field labeled Jet OLEDB.System database.</li> Click Edit Value.</li> <li>In the Property Value box, type the path to the System.mdw file:

C:\Program Files\Common Files\System\System.mdw

NOTE: Alter as necessary if the operating system is not installed on C:\.

</li> <li>Click OK in the Edit Property Value window.</li> <li>Select the field labeled Jet OLEDB:Database Password.</li> <li>Click Edit Value.</li> <li>In the Property Value box, type the password for the System database.</li> <li>Click OK in the Edit Property Value box.</li> <li>Click OK to close the Data Link Properties window.</li></ol>

The final connection string should look like this: Provider=Microsoft.Jet.OLEDB.4.0;Password=joe;User ID=jim;Data Source=C:\My.mdb;Persist Security Info=True; Jet OLEDB:System database=C:\Program Files\Common Files\System\SYSTEM.MDW;Jet OLEDB:Database Password=14323 NOTE: The preceding connection string has been broken into two lines for readability; however, it must be in a single line in your code.

back to the top

Troubleshooting
Although Microsoft does not recommend that you use Internet Information Server (IIS) to connect to Access databases, there are several advantages to using OLE DB versus ODBC for Access database connections. One of the benefits of using OLE DB connections is the ability to connect to databases without the need to create a user or system Data Source Name (DSN) on the Web server. Other advantages include the ability to call a thread-safe version of Microsoft Visual Basic for Applications and increased stability.

back to the top

<div class="references_section">