HOWTO: Modify DataEnvironment Connection Strings at Run-Time

ID: Q221794


The information in this article applies to:


SUMMARY

The DataEnvironment greatly simplifies the process of building queries at design-time. The DataEnvironment requires a connection string at design-time in order to connect to your database. That same connection string is used, by default, in your application.

When you're ready to distribute your application, you may want to modify the connection string used by your DataEnvironment. The simplest way to do this in code is to use the DataEnvironment's Initialize event.


MORE INFORMATION

For example, you may be using an Access database in your application. The DataEnvironment will store the full path to your Access database in the connection string. When you distribute your application, you may want to place the Access database in a subdirectory of your application. You could use the following code in the DataEnvironment's Initialize event to modify the connection string accordingly:


Private Sub DataEnvironment_Initialize()
    Dim strConn As String
    
    strConn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
              "Data Source=" & App.Path & "\Data\MyDB.mdb;"
    DataEnvironment1.Connection1.ConnectionString = strConn
End Sub 


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by David Sceppa, Microsoft Corporation

Additional query words:


Keywords          : kbDatabase kbVBp600 kbDataEnv 
Version           : WINDOWS:6.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: March 30, 1999