Connection 4: Use DriverSelect() to open any connection
<< Click to Display Table of Contents >> Connection 4: Use DriverSelect() to open any connection |
![]() ![]() ![]() |
This sample shows how you can use the same dialog that was used to edit the UDL file in your program to ask the user for a connection. Great for example and utility programs, probably of little use for production applications <g>.
The first paramater of AdoDriverSelect() should be a VO window object or NIL.
FUNCTION Start()
LOCAL sError AS STRING
LOCAL oConn AS AdoConnection
LOCAL cbErr AS CODEBLOCK
LOCAL uError AS USUAL
cbErr := ErrorBlock({|oErr|_Break(oErr)})
BEGIN SEQUENCE
set color TO w+/b
cls
? "Now open the DriverSelect() dialog and choose the driver"
oConn := AdoDriverSelect(NIL)
// Set some additional properties
oConn:ConnectionTimeout := 5
oConn:CursorLocation := adUseClient
RECOVER USING uError
? "Error: "+uError:description
quit
wait
END
BEGIN SEQUENCE
// Try to open
oConn:Open(NIL,NIL,NIL,NIL)
RECOVER USING uError
END
// Restore error handler
ErrorBlock(cbErr)
IF oConn:State <> adStateOpen
// Error occurred
IF oConn:Errors:Count > 0
// Ado Error
sError := oConn:Errors:[Item,1]:Description
ELSEIF IsInstanceOfUsual(uError, #Error)
sError := uError:Description
ELSE
sError := "Unknown error"
END IF
? "Error when making connection: ", sError
ELSE
? "Connection succesfull:"
? "Provider: "+oConn:Provider
? "Database: "+oConn:DefaultDatabase
? "String : "+oConn:ConnectionString
ENDIF
wait
RETURN