Difference between revisions of "QuickOPC.NET: How to log OPC Data Access item changes into a SQL Server database"

From OPC Labs Knowledge Base
Jump to navigation Jump to search
(Created page with " It is often required that a status of certain process variable is logged into a SQL database. Following example shows how to do that with QuickOPC: The database creation scr...")
 
Line 18: Line 18:
  
 
And (part of) the resulting data may look like this:
 
And (part of) the resulting data may look like this:
+
[[File:howtologopcdataaccessitemchangesintoansqldatabase.png|center]]
  
 
This example is included with the product. Please use the example from the product itself for the most up-to-date code of the example.
 
This example is included with the product. Please use the example from the product itself for the most up-to-date code of the example.

Revision as of 14:43, 31 July 2016

It is often required that a status of certain process variable is logged into a SQL database. Following example shows how to do that with QuickOPC:

The database creation script is here:

-- Creates a database with tables needed to run QuickOPC examples.
CREATE DATABASE QuickOPCExamples;
GO
USE QuickOPCExamples;
GO
CREATE TABLE SimpleLog (
 ItemID nvarchar(50) NULL,
 Value sql_variant NULL,
 [Timestamp] datetime NULL,
 Quality int NULL
);
GO

And (part of) the resulting data may look like this:

Howtologopcdataaccessitemchangesintoansqldatabase.png

This example is included with the product. Please use the example from the product itself for the most up-to-date code of the example.

General information about integration of QuickOPC and Microsoft SQL Server is here.

OPC Alarms and Events notifications can be logged using the same approach, with EasyAEClient component.


Update: The original example (SimpleLogToSql) stores values of all data types in a single SQL_VARIANT column. We are now including two additional examples of SQL logging with the product:

  • LogAsString: Values of all data types are stored in a single NVARCHAR column.
  • LogAsUnion: Values of all data types are stored in separate columns.