Microsoft KB Archive/288106

= How To Use a UDL File for Hierarchical Commands in the Data Environment =

Article ID: 288106

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q288106



SUMMARY
This article explains how to use a Universal Data Link (UDL) file in place of a connection string in the Data Environment with hierarchical or grouped Command objects.

Normally, a UDL file can be used with a Data Environment Connection by changing the ConnectionSource property manually to point to the UDL file by using the &quot;File Name=&quot; argument, as follows: File Name=C:\MyFolder\MyUDLFile.udl However, this approach does not work with Command hierarchies.



MORE INFORMATION
When a Data Environment Connection must service hierarchical Command objects, the connection string that is entered by the developer at design time is modified in a hidden manner at run time to use the MSDataShape data shaping service provider in front of the originally specified provider (for example, the Microsoft Jet or the SQLOLEDB provider).

Although the Data Environment handles this modification properly with an ordinary connection string, the Data Environment does not handle this modification correctly if the developer has manually specified a UDL file as the ConnectionSource. The modified connection string that results is invalid, and, although no error message may be generated, no data is retrieved.

You can work around this limitation and still rely on a UDL file by using two Connection objects: one for &quot;ordinary&quot; Commands, and a second for hierarchical or grouped Commands. This is demonstrated in greater detail in the following example. The outline of steps is as follows:
 * 1) Open the first connection for ordinary Commands by using the desired UDL file.
 * 2) Create a new connection string based on this connection string, adding the arguments necessary to use the MSDataShape provider.
 * 3) Assign this new connection string to the second connection for hierarchical Commands.

Example
 Create two identical Connections in your Data Environment and specify the connection information by using the Data Link Properties dialog box. Create your ordinary Commands under Connection #1. Create your hierarchical or grouped Commands under Connection #2. Right-click on the Windows Desktop, in Microsoft Data Link choose New, and then specify the connection information to create a UDL file for your database. Select Connection #1 in the Data Environment, and then change the ConnectionSource property in the Properties window to point to the UDL file by using the &quot;File Name=&quot; syntax shown earlier. Select Connection #2, and then delete the existing contents of the ConnectionSource property. Note that you are now supplying this value programmatically. Open the code window for the Data Environment, and then select the Data Environment's Initialize event.</li>  Enter the following code for the Initialize event, adjusting the names of the Data Environment and the Connection objects as necessary: DataEnvironment1.Connection2.ConnectionString = &quot;Provider=MSDataShape;Data &quot; & DataEnvironment1.Connection1.ConnectionString If your original connection string is &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyFolder\MyDatabase.mdb&quot; then the new connection string you have for your hierarchical Command object is: &quot;Provider=MSDataShape;Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyFolder\MyDatabase.mdb&quot; </li> Run and test your project.</li></ol>

<div class="references_section">