Access an OLE DB or ODBC data source
- Last UpdatedApr 24, 2025
- 1 minute read
Data can be obtained from a variety of Object Linking and Embedding database (OLE DB) and Open Database Connectivity (ODBC) data sources, such as the Microsoft SQL Engine and Microsoft SQL. Returned data can even be forwarded to the client. The following example queries the RealTime database (RTDB) for a list of analog points belonging to the cmsgroup1 group. It then returns this list to the client.
Example: Executing a query against the RTDB
using OASySDNA.Common.Config;
using OASySDNA.Common.DAL.ClientSDK;
using OASySDNA.Common.DAL.ServerUtilities;
DNAService dnaService = new DNAService ("Realtime", DNAEnvironment.SystemName);
string szADOConnectString;
//= dnaService.GetFQADOString();
DALService.Initialize(DNAEnvironment.SystemName);
szADOConnectString = SQLDriver.GetADOConnectionString("Realtime");
DALService.Shutdown();
// Connect to the Realtime database
ADODB.Connection conRealtime = new ADODB.ConnectionClass();
conRealtime.Open(szADOConnectString,"","",0);
ADODB.RecordsetClass rsReturn = new ADODB.RecordsetClass();
rsReturn.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
rsReturn.Open("select name,curval from analog where \"group\" = 'cmsgroup1'", conRealtime,ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic,0);
// Disconnect the recordset from the source
rsReturn.ActiveConnection = null;
// Close the connection
conRealtime.Close();
// Create a new BLTRecordset from the results
BLTRecordset bltrsResults = new BLTRecordset();
bltrsResults.Recordset = rsReturn;
// Return the recordset to the client
this.AddRecordset(bltrsResults);