In version 2.0 of the Microsoft Data Access Components,
Data Links were introduced. Data Link files are similar to ODBC DSN files, but
allow you to select an OLE DB provider to connect to your database. With the
OLE DB Provider for ODBC drivers, you can also connect to an ODBC data
source.
Double-clicking on a Data Link file displays a set of
property pages that allow you to build a connection string to connect to your
database.
You can use this same functionality in your Visual Basic
applications by following the steps listed below:
- Launch Visual Basic and open a new Standard Exe project.
Form1 is created by default.
- Select References from the Project menu, and then select
Microsoft OLE DB Service Component 1.0 Type Library from the list of available
references.
- Add a CommandButton to your form.
- Add the following code to the Click event of your
CommandButton:
Private Sub Command1_Click()
Dim objDataLink As New DataLinks
Dim strConn As String
strConn = objDataLink.PromptNew
MsgBox "The connection string you created is:" & _
vbCrLf & strConn
End Sub
- Run the project.
When you click the CommandButton, you will see the Data Links
property pages. Once you have specified how you want to connect to your
database and click the OK button, you'll see the connection string in a dialog
box.