Skip to content

OPC Router Tutorial SQL

Following the first part of the OPC Router tutorial, I’m presenting how to connect an OPC DA server to Microsoft SQL Server now. Remember, we’re configuring and running a project for “Papín”, a fictional potato bread factory.

Why an OPC Router tutorial with SQL?

Because “learning by doing” with examples is fun. See below a list of posts that complete this tutorial:

  1. Getting Started with OPC Router
  2. Connect an OPC DA server to Microsoft SQL Server (this post)
  3. Connect an MQTT data source to InfluxDB Cloud
  4. Perform multiple calculations within OPC Router
  5. Run an OPC Router application with Linux and Docker
  6. Build a process data simulator with Python, CSV and OPC Router
  7. Explore basic RESTful web services within OPC Router
  8. Build a Telegram basic interaction within OPC Router
  9. Build an SMS basic interaction within OPC Router
  10. Build a WhatsApp basic interaction within OPC Router
  11. Build a Teams basic interaction within OPC Router
  12. Explore advanced RESTful web services within OPC Router
  13. Run an OPC Router application with Portainer

Working with OPC Router, OPC Classic, and SQL Server

Knowing your Plugins

  • To begin with, the configuration of OPC Router starts with your licensed plugins. There are several categories such as “Cloud / IoT”, “Topfloor”, “Shopfloor”, “Storage”, “Advanced”, “Messaging” and “Printer”.
opc router tutorial sql 1
opc router tutorial sql 2
  • Make sure to notice OPC Classic and MS SQL.

Checking your Plugins

  • Following identification, OPC Router needs to configure every licensed plugin. Let’s check the plug-in instance with OPC Classic (double click on the object):
opc router tutorial sql 3
  • At this point, check a local OPC Classic connection using a Factory Talk Linx Gateway OPC DA server, with an update rate of 6 seconds.
opc router tutorial sql 4
  • After that, let’s check the plug-in instance with MS SQL:
opc router tutorial sql 5
  • Then, check the local Microsoft SQL Server database storage and press the “Check connection” button to test connectivity.
opc router tutorial sql 6
opc router tutorial sql 7

Creating your Second Template

  • In similar fashion to the first part of the tutorial, a template is the correct approach once again. Let’s create a new INSERT to database template MCurr within IDB folder (VSD motor current):
opc router tutorial sql 8
opc router tutorial sql 9
  • Observe an empty design panel so you can start building your template:
opc router tutorial sql 10
  • Drag and drop all blocks as shown here:
opc router tutorial sql 11
  • Insert the Database block:
opc router tutorial sql 12
opc router tutorial sql 13
  • Make sure your table [pv].[tb_rv_vsd_motor_i] complies with the following design:
opc router tutorial sql 14
  • Edit the INSERT operation and make sure it looks like this:
opc router tutorial sql 15
opc router tutorial sql 16
  • Make sure to link blocks as shown here to complete your second template:
opc router tutorial sql 17

Working with Instances from Templates

  • With your second template, a new instance is required now. Start creating it using the contextual menu:
  • Check the new instance:
  • In the design panel, double-click to check values in template variables according to the actual OPC item and location:

Compile, Save and Publish your OPC Router Project Configuration with OPC Classic and SQL Server

  • At this time, you need to compile, save and publish the connection you just created by clicking the “Go productive” button:
  • Meanwhile, the project is saved and published.
  • Press the “Yes” button to start the OPC Router service and run your application.

Check Compiled Connection State

  • Finally, you should check the state of your compiled connection by pressing the “State” button:
  • You should notice an execution time visually (it’s 79.10 milliseconds in this example):

Visualize Online Values

  • Also, you can watch live values here:

Verify OPC Router Data Transfer from OPC Classic to SQL Server

  • Additionally, you can verify data transfer within the SQL Server by running SSMS:

Control OPC Router service

  • You are able to start, stop or restart the OPC Router service when needed.

Did you enjoy this OPC Router tutorial with SQL? I’d love to hear from you.

Stay tuned and follow part 3 of this tutorial! 😎

For other articles like this one in English, click here. To see them in Spanish, click here.

Share this post