How to access relational databases from WinCC OA Ctrl with CtrlADO and ODBC...


There is a ctrl library delivered with WinCCOA named "rdb.ctl" which offers you a set of
functions to easily access relational databases!


You will find the Library in the installation directory of WinCCOA, for example here:
D:\Siemens\WinCC_OA\3.10\scripts\libs\rdb.ctl

Create an odbc data source (DSN) "mydb" in your (for example) windows environment and try this example:

#uses "CtrlADO.dll"
#uses "rdb.ctl"
main()
{
dbConnection db;
dyn_dyn_anytype res;
rdbOpen(db, "DSN=mydb;UID=scott;PWD=tiger");
rdbSelect(db, "SELECT * FROM emp", res); DebugTN(res);
rdbExecute(db, "UPDATE emp SET sal=sal*0.10");
rdbSelect(db, "SELECT * FROM emp", res); DebugTN(res);
rdbClose(db);
}

But be carefully with rdbSelect. The result is loaded into a dyn_dyn_anytype into the memory. Don't fetch millions of rows...

Last update:
2014-09-09 19:00
Author:
Andreas Vogler
Revision:
1.0
Average rating: 4.6 (5 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.