How to connect to WinCC OA HISTVAL table values from Visual Studio

Find and share HowTos to various installations / configurations!
5 posts • Page 1 of 1
ubusto
Posts:11
Joined: Tue Apr 05, 2016 9:55 am

How to connect to WinCC OA HISTVAL table values from Visual Studio

Post by ubusto »

Hi,

I need to read the historical data from the WinCC OA 3.13 Histval table from an application developed using Visual Studio,
for this purpouse i have registered WCCOAoledb.WCCAoledb in windows\\system32

the code i am testing is the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
using ADODB;


namespace BD_WINCCOA
{
class Program
{
static void Main(string[] args)
{
try {
string strProvider = "Provider = WCCOAoledb.WCCOAoledb;Data Source=localhost:4444";
string strSql = " SELECT DPNAME FROM HISTVAL";

ADODB.Connection con = new ADODB.Connection();
ADODB.Command cmd= new ADODB.Command();
ADODB.Recordset rs = new ADODB.Recordset();
object recs;
cmd.CommandText = strSql;

Console.WriteLine("Before Connecting");
con.Open(strProvider, "", "", -1);
Console.WriteLine("Connected");

rs = con.Execute(strSql,out recs, 0);

Console.WriteLine(rs.RecordCount + " registers!");
con.Close();
}

catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}

finally
{
Console.WriteLine("Click to close");
Console.ReadKey();
}
}
}
}

Thx in advance for your help.

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: How to connect to WinCC OA HISTVAL table values from Visual Studio

Post by leoknipp »

Hello,

from the description I cannot see what the problem is.
Do you get an error when executing the function?
Have you tried to read data using the SampleHistDB.xls file (source directory at the WinCC OA installation)?

The example for WinCC OA version 3.13 is using the wrong name for the OLE-DB-file.
In the newest version 3.14 it is already corrected.

Instead of
Set oADOConn = New ADODB.Connection
oADOConn.Open "Provider = PVSSoledb.PVSSoledb"

the following code needs to be used
Set oADOConn = New ADODB.Connection
oADOConn.Open "Provider = WCCOAoledb.WCCOAoledb"

Please modify the code on your own when using this example.

Best Regards
Leopold Knipp
Senior Support Specialist

ubusto
Posts:11
Joined: Tue Apr 05, 2016 9:55 am

Re: How to connect to WinCC OA HISTVAL table values from Visual Studio

Post by ubusto »

Hi,

thx for reply.
I am trying to connect but i get an error saying: The 'WCCOAoledb.WCCOAoledb' is not registered on the local machine.
I am capable of reading data using the SampleHistDB provided and even with the Database browser program i can connect to the database.

But when i try to connect to the database using the same connection in a program developed from me i get the error described above.

It would be very appreciated if you could provide me more information about how a third party program can connect to the database, i mean, if there is a specific .NET framework that should be used or maybe an specific oledb.dll must me registered, or whatever information you think it would be important to know.

thx in advance.

fandersen
Posts:51
Joined: Tue Aug 26, 2014 12:39 pm

Re: How to connect to WinCC OA HISTVAL table values from Visual Studio

Post by fandersen »

Hi Urko,

have you checked your build target setting (x86, x64) in visual studio?

If you are using the setting AnyCPU your application runs in the OS "native" format which is 64bit for an x64-OS and 32bit for an x86-OS. Running an application in x86 or x64 also makes a difference in which registry hive your application is looking for the 'WCCOAoledb.WCCOAoledb' registration.

Where can I get this dll to test it?


Best Regards
Florian

ubusto
Posts:11
Joined: Tue Apr 05, 2016 9:55 am

Re: How to connect to WinCC OA HISTVAL table values from Visual Studio

Post by ubusto »

thx sir,

this worked for me!!!

5 posts • Page 1 of 1