OLE-DB providers are offered by various sources:
Microsoft | Other vendors | |
|
|
|
Some samples:
oConn:Open("DSN=AdvWorks;UID=Admin;PWD=;",NIL,NIL,NIL)
oConn:Open("Provider=Microsoft.Jet.OLEDB.4.0;" + ;
"Data Source=.mdb;User Id=admin;Password=;",NIL,NIL,NIL)
oConn:Open("Provider=sqloledb;" + ;
"Data Source=robert;Initial Catalog=pubs;User Id=sa;Password=;",NIL,NIL,NIL)
Another very good source of information is the ADO FAQ website that you can find at: http://www.able-consulting.com/ADO_Faq.htm
A detailed explanation of these tips can be found on the Ms website.
The following code contains two functions. One function to install an ODBC driver (in this case the SqlServer driver) and One function to install an ODBC datasource (DSN).
// This writes the connection info FUNCTION WriteConnToRegistry(cDSN AS STRING, cServer AS STRING, cDatabase AS STRING) LOCAL pszFile AS PSZ LOCAL lOk AS LOGIC LOCAL pszDSN AS PSZ pszDSN := String2Psz(cDSN) pszFile := String2Psz("ODBC.INI") SQLWriteDSNToIni(String2Psz(cDSN), String2Psz("SQL Server")) lOk := SQLWritePrivateProfileString(pszDSN, String2Psz("Server"), String2Psz(cServer), ; pszFile) lOk := lOk .and. SQLWritePrivateProfileString(pszDSN, String2Psz("Database"), ; String2Psz(cDatabase), pszFile) lOk := lOk .and. SQLWritePrivateProfileString(pszDSN, String2Psz("AutoTranslate"), ; String2Psz("Yes"), pszFile) RETURN lOk // this makes sure the driver is there and installs it FUNCTION InstallSQLServer() LOCAL cDriverInfo AS STRING LOCAL cDLL AS STRING LOCAL pszPath AS PSZ LOCAL cSystemDir AS STRING LOCAL lLen AS LONG LOCAL lOk AS LOGIC cSystemDir := SystemDirectory() cDLL := AddSlash(cSystemDir)+"SQLSRV32.DLL" IF ! File(cDLL) Warning("Cannot find SQL Server ODBC Driver: "+cDLL) lOk := TRUE ELSE cDriverInfo := "SQL Server"+_chr(0)+ ; "Driver=SQLSRV32.DLL"+_chr(0)+ ; "Setup=SQLSRV32.DLL" +_chr(0)+ ; "APILevel=1"+_chr(0)+ ; "ConnectFunctions=YYN"+_chr(0)+ ; "SQLLevel=1" + _chr(0) + _chr(0) pszPath := MemAlloc(_MAX_PATH) lOk := SQLInstallDriver(NULL, String2Psz(cDriverInfo), pszPath, _MAX_PATH,lLen) MemFree(pszPath) IF ! lOk Warning("Cannot Install driver ") ENDIF ENDIF RETURN lOk // ODBC API _DLL FUNCTION SQLInstallDriver(pszInfFile AS PSZ, pszDriver AS PSZ, pszPath AS PSZ, ; liPathMax AS LONG, liPathOut AS LONG) ; AS LOGIC PASCAL:odbccp32.SQLInstallDriver _DLL FUNCTION SQLInstallDriverManager(pszPath AS PSZ, liPathMax AS LONG, liPathOut AS LONG) ; AS LOGIC PASCAL:odbccp32.SQLInstallDriverManager _DLL FUNCTION SQLRemoveDSNFromIni(pszDSN AS PSZ) AS ; LOGIC PASCAL:odbccp32.SQLRemoveDSNFromIni _DLL FUNCTION SQLWriteDSNToIni(pszDSN AS PSZ, pszDriver AS PSZ) AS ; LOGIC PASCAL:odbccp32.SQLWriteDSNToIni _DLL FUNCTION SQLWritePrivateProfileString(pszSecrion AS PSZ, pszEntry AS PSZ, ; pszValue AS PSZ, pszFile AS PSZ) AS LOGIC PASCAL:odbccp32.SQLWritePrivateProfileString _DLL FUNCTION SQLConfigDataSource (hWndParent AS PTR, liRequest AS LONG, ; pszDriver AS PSZ, pdzAttributes AS STRING) ; AS LOGIC PASCAL:odbccp32.SQLConfigDataSource
Unfortunately recordset:Find in Ado is limited to a single expression. RecordSet:Filter on the other hand allows more complex filters.
If you don't want to set a filter on your recordset you can try to clone
the recordset, set a filter on the clone and read the bookmark from the
clone.Something alonge the lines of:
oRs2 := oRs:Clone(adLockReadOnly) oRs2:Filter := "ModelKey=" + ntrim(nModelKey) + " and subtype like '" + cSubType + "'" oRs2:MoveFirst() oRs1:BookMark := oRs2:BookMark oRs2:Destroy()
Yes you can use Xs2Ado to access Access databases. You need to use the Microsoft.Jet OLEDB Provider that you can download (and distribute) for free from the Microsoft Website.
Then you need a connectionstring that looks like:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\myapp\mydata.mdb;"