Calling a Stored Procedure - Tag Editor


I have a script that runs perfect from the Script Console. The code is this:


Basically just calls a Stored Procedure in my MS SQL DB.

Now I want this same code to trigger when a tag from MQTT Engine changes. So in the Tag Editor, under Scripting I add the same code but it never executes. I get this error message:

Error executing script.
Traceback (most recent call last):
File "tagevent:valueChanged", line 2, in valueChanged
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(
at jdk.internal.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.execSProcCall()

Any idea why it works in the Script Console, but not for Tag Scripting?

Hi @Carsten_Dressler, welcome!

I believe the reason why is because since you're calling the createSProcCall function from the gateway scope, you need to pass in the database parameter.

Here is a snip of the docs:

So, to resolve this, pass in the name of your database connection and that may fix it.

system.db.execSProcCall(system.db.createSProcCall("sp_test", "<database_connection_name>"))
1 Like

More specifically - you're in a tag event script. Tags are always running, and outside the "context" of any particular project - so there is no default database for them to use.