Database - Script Database Connection​

Script Database Connection​

In this chapter the user will be shown different ways to query the database without using the “Global Database Connection”.

Using .NET Data Provider

The scripts can be written inside a button, user function, service, and trigger.  Depending on the database, a different class object will be used.
The examples below can only be used to connect to a PostgreSQL database.

  • The following example creates a table called inside the PostgreSQL database.

  • The above example is a “UserFunction”.  The first parameter of this function is used to create the table name and the second parameter, in case it is true, will drop the table before its created.
  • The next code inserts values into a PostgreSQL table.

Using SVDBConnection

The user may also use the “SVDBConnection” within the System Function Library to run queries.  It is similar to the example in the “Using SVDBConnection Functions” section, but in this current example the user will need to provide the connection string and the provider.
Please take a look at the example below.  It will select values from a Microsoft SQL Server table and add those values to a dynamic array tag.  This is an alternative database query approach.

  • The SHIFTS data type contains the following tags:

  • The following script was inserted in a Service. As it was already detailed, it will connect to a Microsoft SQL Server table, select all the values and create new entries into the dynamic array tag.

  • The dynamic array tag to be associated with a MultiTagViewer object will display the values from the database during runtime.

  • Let’s run the application to check the values selected.

Scroll Up