Connection Objects

See Also

To access data using your Data Environment, you must create a Connection object. Therefore, every Data Environment should include at least one Connection object. A Connection object represents a connection to a remote database that is used as a data source.

Upon adding a Data Environment to your Visual Basic project, the Data Environment designer automatically includes a new connection, called Connection1. At design time, the Data Environment opens the connection and obtains metadata from the connection, including database object names, table structures, and procedure parameters.

Note   If Show properties immediately after object creation is selected in the Options dialog box, the Data Link Properties dialog box will appear when you add a Data Environment to your project. This option is not selected by default.

Creating a Connection Object

The Add Connection function is available at all times and is independent of the existence of other objects.

To create a database connection

To set the Connection Name and Data Source

  1. In the Visual Basic Properties window, change the default Name to a more meaningful name for your data source database. For example, you may wish to change Connection1 to "Northwind" if the data source is the Northwind database.

  2. Right-click the Connection object and choose Properties to access the Data Link Properties dialog box.

  3. From the Data Link Properties dialog box, specify the connection information on the Provider and Connection tabs. This is typically a database that contains data or stored procedures. You may select only one source for each Connection object.

    Note   Regardless of the selected data source type, the Data Environment accesses all data via ADO and OLE DB interfaces.

  4. Click OK to apply the properties and close the dialog box.

Setting Logon Information

Logon information only needs to be supplied if the database being accessed via the Connection object requires authentication information. You can specify a different set of logon information to be used at design time and run time. For example, you might want to develop your application using a system administrator user identification and password, but supply a general guest user identification when the application is run.

Note   Any logon information specified on the Data Link Properties dialog box is overridden by logon information specified on the Visual Basic Properties window.

To specify logon information

  1. On the Visual Basic Properties window, specify the user identification and password to be used at design time and run time, if necessary. You can also specify the prompt behavior.

  2. Set DesignSaveAuthentication to True if you want the specified information to persist for design time. This information is not written into the built executable file or dynamic-link library (DLL). If this option is False, any information in DesignUserName and DesignPassword is lost once you close and re-open the project.

  3. Set RunSaveAuthentication to True if you want the specified authentication used at run time. The authentication information is stored in the properties of the class and persists in the built executable file or DLL. If this option is False, any information in RunUserName and RunPassword is lost once you close and re-open the project.

    Note   Since the password is not encrypted, for maximum security you should not specify your password to persist for run time or design time.

Setting Miscellaneous Connection Information

The miscellaneous connection information consists of advanced options that change how the database is accessed.

To specify miscellaneous information

  1. On the Visual Basic Properties window, specify the following:
  2. Right-click the Connection object and choose Properties to access the Data Link Properties dialog box.

  3. On the Advanced and All tabs, you can:
  4. Click OK to apply the properties and close the Data Link Properties dialog box.

    Note   A Connection object is not opened until information is needed from the connection, such as a list of tables. When a Connection object is selected in the Data Environment outline view, the status bar text can be used to determine if the connection is currently established (open).

Dragging From a Data View to Your Data Environment

You can automatically create Connection objects by dragging a connection from the Data View window to your Data Environment designer. This is an easy and efficient way to create Connection objects that already exist in your Data View.