Article ID: 194960
Article Last Modified on 6/29/2004
* Begin code
* The following program creates a DSN-less connection using
* an existing SQL Server driver. Substitute your own SQL
* server, database, user id and password parameters in the
* definition of the lcConnString variable.
*
* The program then attempts to create an asynchronous connection
* to this server, waiting in a loop until the Connection object's
* state property is no longer attempting to connect.
#DEFINE adAsyncConnect 16
#DEFINE adStateConnecting 2
#DEFINE adUseClient 3
#DEFINE adModeReadWrite 3
#DEFINE CR CHR(13)
lcConnString = "driver={SQL Server};" + ;
"SERVER=YourServerName;" + ;
"DATABASE=YourDatabaseName;" + ;
"UID=YourUserID; " + ;
"PWD=YourPassword"
oConnection = CREATEOBJECT("ADODB.Connection")
WITH oConnection
.CommandTimeout = 60
.ConnectionTimeout = 30
.ConnectionString = lcConnString
.CursorLocation = adUseClient
.Mode = adModeReadWrite
ENDWITH
oConnection.Open(,,, adAsyncConnect)
DO WHILE oConnection.State = adStateConnecting
WAIT WINDOW NOWAIT "Still connecting"
ENDDO
WAIT CLEAR
? "Connection completed"
lcTitle = "Default connection properties"
lcText = "Attributes: " + LTRIM(STR(oConnection.ATTRIBUTES)) + CR + ;
"Command Timeout: " + LTRIM(STR(oConnection.CommandTimeout)) + CR + ;
"Connection String: " + oConnection.ConnectionString + CR + ;
"Connection Timeout: " + ;
LTRIM(STR(oConnection.ConnectionTimeout)) + CR + ;
"Cursor Location: " + ;
LTRIM(STR(oConnection.CursorLocation)) + CR + ;
"Default Database: " + oConnection.DefaultDatabase + CR + ;
"Isolation Level: " + LTRIM(STR(oConnection.IsolationLevel)) + CR + ;
"Mode: " + LTRIM(STR(oConnection.Mode)) + CR + ;
"Provider: " + oConnection.Provider + CR + ;
"State: " + LTRIM(STR(oConnection.State)) + CR + ;
"Version: " + oConnection.VERSION
=MESSAGEBOX(lcText)
* End code
The constants used were defined using the Microsoft Visual Basic 6.0 object browser.
Keywords: kbhowto kbdatabase KB194960