Connection 2: MsJet Connection
<< Click to Display Table of Contents >> Connection 2: MsJet Connection |
![]() ![]() ![]() |
This sample shows the syntax to open a MsJet database using ADO:
Connection Strings for other providers can be found in the Ado connections topic or the other samples.
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
oConn := AdoConnection{}
oConn:ConnectionTimeout := 5
oConn:provider := "Microsoft.Jet.OleDb.4.0"
oConn:Properties:[item, "Prompt"]:Value := AdPromptComplete
// MS Jet
oConn:ConnectionString := "Data Source=C:\Vo2Ado26\Northwind.mdb;" +;
";User Id=Admin;Password=;"
oConn:CursorLocation := adUseClient
RECOVER USING uError
? "Error: "+uError:description
quit
wait
END
BEGIN SEQUENCE
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