Some content on this site is available only to logged-in subscribers. Contact Us for information on becoming a subscriber.

InSource.Solutions | InSource Training | InSource Client Portal
InSource Solutions Logo
Log In Sign Up
InSource.Solutions InSource Training InSource Client Portal Log In Sign Up
  • Home
  • AVEVA Application Server
  • AVEVA Application Server Tech Notes

Application Server script that executes a SQL non-query stored procedure

Last updated: February 24th, 2025

Description

  • Author: Brian Schneider
  • Published: February 24th, 2025

Details:

Overview

A script that executes a SQL Stored Procedure that has both input parameters and an output parameter that returns an error code

Resolution

UDAs for this Database Object

Debug

Boolean

RecordsAffected

Integer

SQLErrorMsg

String

Trigger

Boolean

Script Configuration

Script Name:

InsertDB

Execute Type:

Execute

Expression:

Me.Trigger

Trigger Type:

OnTrue

Run async

(checked)

Declarations

dim dt AS System.Datetime;
dim SQLConnection as System.Data.SqlClient.SqlConnection;
dim SQLCommand as System.Data.SqlClient.SqlCommand;

Script

me.Trigger = False;
me.SQLErrorMsg = "";
me.RecordsAffected = 0;

Dim iRC As Integer;
Dim sDateTime As String;
Dim sQuery As String;

dt = Now();
sDateTime = (dt.ToString("MM/dd/yyyy HH:mm:ss"));

' --- Could/Should replace with UDAs here --------------
Dim iBatchID As Integer;
Dim rActual As Float;
Dim rTarget As Float;
Dim sItem As String;

iBatchID = 23;
sItem = "Weight";
rActual = 51.1;
rTarget = 50.0;
' -----------------------------------------------

SQLConnection = new System.Data.SqlClient.SqlConnection(MyContainer.ConnectStr);
SQLConnection.Open();

sQuery = "BatchRecordInsert" ; '' Enter the stored procedure name here

SQLCommand = new System.Data.SqlClient.SqlCommand(sQuery, SQLConnection);
SQLCommand.CommandType = System.Data.CommandType.StoredProcedure;

SQLCommand.Parameters.Add("@BatchDateTime", System.Data.SqlDbType.datetime);
SQLCommand.Parameters("@BatchDateTime").Value = sDateTime ;

SQLCommand.Parameters.Add("@BatchID", System.Data.SqlDbType.int);
SQLCommand.Parameters("@BatchID").Value = iBatchID ;

SQLCommand.Parameters.Add("@Item", System.Data.SqlDbType.varchar,18) ;
SQLCommand.Parameters("@Item").Value = sItem ;

SQLCommand.Parameters.Add("@Actual", System.Data.SqlDbType.float) ;
SQLCommand.Parameters("@Actual").Value = rActual ;

SQLCommand.Parameters.Add("@Target", System.Data.SqlDbType.float);
SQLCommand.Parameters("@Target").Value = rTarget;

SQLCommand.Parameters.Add("@Err", System.Data.SqlDbType.Int) ;
SQLCommand.Parameters("@Err").Direction = System.Data.ParameterDirection.Output ;


if me.Debug then
   LogMessage( "Insert About to Execute: " + SQLCommand );
endif;

me.RecordsAffected = SQLCommand.ExecuteNonQuery();

iRC = (SQLCommand.Parameters("@Err").Value) ;

SQLConnection.Dispose();


if me.Debug then
   LogMessage( "Insert Submitted ...Records Affected: " + Text(me.RecordsAffected,"#"));
   LogMessage( " *** SQL Err Code: " + StringFromIntg( iRC, 10 ) + " -:- SQL Error Message: " + me.SQLErrorMsg );
endif;

 

sql procedure server script
Give feedback about this article

Recommended articles

TN 1242 Aveva Historian Storage Locations and Best Practices

Read More

TN 1393 Deleting Tags from AVEVA Insight

Read More
Support Icon

CONTACT SUPPORT

How to reach us

10800 Midlothian Turnpike Tpke, Suite 209, Richmond, VA 23235

1.877.INSOURCE

Technical Support - 1.888.691.3858

Contact Us

  • InSource Solutions
  • InSource Training
  • InSource Client Portal
  • Log In
InSource Solutions Logo

© 2025 InSource Solutions. All Rights Reserved.

Knowledge Base Software powered by Helpjuice

Expand