juan
Ms Access connects very nicely using Ms Jet rather than ODBC. Ms Jet is the OleDb provider native to all Windows machines.
My suggestion is to create your initial connection like this :
Code: Select all
Local xProvider,xSource,xPassword,xString,oConnect
Local oRsStaff,oErr,cSql
Local cDefa
Public oConnection
cDefa := "\\server\volume\share" // just using a unc if you are not connecting to a local database
xPROVIDER := "Microsoft.Jet.OLEDB.4.0" // oledb provider for access
xSOURCE := cDEFA+"\Your.mdb" // path to access database including the database name
xPASSWORD := "xxxxxxxx" // optional database password
xSTRING := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD // connection string
// create your global connection
oConnect := CREATEOBJECT( "ADODB.Connection" )
TRY
oConnect:Open( xString )
CATCH oErr
Saying := "Could not open a Global Connection to Database "+xSource
MsgInfo( Saying )
RETURN(.F.)
END TRY
// then use these parameters to open your record sets with the public connection object
oRsStaff := TOleAuto():New( "ADODB.Recordset" )
oRsStaff:CursorType := 1 // opendkeyset
oRsStaff:CursorLocation := 3 // local cache
oRsStaff:LockType := 3 // lockoportunistic
cSql := "Select [StaffEid],[Lname],[Fname],[FullName],[Active] From [Staff] "
cSql += "where [Active] = 'Y' Order by Fname,Lname"
TRY
oRsStaff:Open( cSQL,oCONNECT )
CATCH oErr
MsgInfo( "Error in Opening Staff table" )
RETURN(.F.)
END TRY
xBrowse( oRsStaff )
oRsStaff:Close()
Now that you have your global connection you can open and close as many recordsets as you like throughout your program and the database will only see one connection.
Tip .. always use the local cache option for best performance.
Rick Lipkin