HOWTO: ODBC and OLEDB Connection Prompt Control in ADO
ID: Q193128
|
The information in this article applies to:
-
ActiveX Data Objects (ADO), versions 1.0, 1.5, 2.0, 2.1 SP2
SUMMARY
This article demonstrates how to prompt a user for ODBC connect string
information such as Server, User ID, Password, Trusted_Connection,
Language, and Database using ActiveX Data Objects (ADO).
The article also shows how to display an OLE DB Data Link dialog box to select an OLEDB provider and its properties.
MORE INFORMATION
ODBC Connect String
The following ADO example uses a "DSN-less" ODBC connection so you do not
need to set up a data source name (DSN) with the ODBC Admin utility.
- In Visual Basic 6.0, add a project reference to the Microsoft ActiveX
Data Objects Library.
- Paste the following code into the Sub Form_Load() section of a new form or another place in your Visual Basic code:
Dim conn As ADODB.Connection
Dim strConn As String
' Assign the connection string to a variable.
strConn = "DRIVER={SQL Server};SERVER=;UID=;PWD=;DATABASE="
' Create the Connection object.
Set conn = New ADODB.Connection
'Assign the connection string and provider, then open the connection.
With conn
.ConnectionString = strConn
.Provider = "MSDASQL"
' Valid Enums for the ADO Prompt property are:
' adPromptAlways = 1
' adPromptComplete = 2
' adPromptCompleteRequired = 3
' adPromptNever =4
.Properties("Prompt") = adPromptAlways
.Open strConn
End With
OLEDB Data Link Dialog Box
- Set project references to the Microsoft OLE DB Service Component 1.0 Type Library and Microsoft ActiveX Data Objects Library.
- Use the following code to open a data link dialog box and print the connection string in the immediate window:
Private Sub btnRunTest_Click()
Dim conn As New ADODB.Connection
Dim dl As New MSDASC.DataLinks
conn = dl.PromptNew
Debug.print conn.ConnectionString
End Sub
Additional query words:
ADO ODBC OLEDB PROMPT DataLink
Keywords : kbADO100 kbADO150 kbADO200 kbDatabase kbODBC kbOLEDB kbProvider kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2
Version : WINDOWS:1.0,1.5,2.0,2.1 SP2
Platform : WINDOWS
Issue type : kbhowto