Microsoft KB Archive/221794

{|
 * width="100%"|

HOWTO: Modify DataEnvironment Connection Strings at Run-Time

 * }

Q221794

-

The information in this article applies to:


 * Microsoft Visual Basic Professional Edition for Windows, version 6.0
 * Microsoft Visual Basic Enterprise Edition for Windows, version 6.0

-

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

Issue type : kbhowto

Technology :