# Calling a Stored Procedure - Tag Editor

**URL:** <https://forum.inductiveautomation.com/t/calling-a-stored-procedure-tag-editor/71457>\
**Category:** Ignition\
**Created:** [March 22, 2023, 6:48pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-tag-editor/71457 "2023-03-22T18:48:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carsten\_Dressler](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@Carsten\_Dressler](https://forum.inductiveautomation.com/u/Carsten_Dressler)\
**Post date:** [March 22, 2023, 6:48pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-tag-editor/71457/1 "2023-03-22T18:48:21Z")

</div>

Hello,

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

```auto
system.db.execSProcCall(system.db.createSProcCall("sp_test"))

```

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(AbstractDBUtilities.java:392)  
> at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(AbstractDBUtilities.java:530)  
> 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()

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1b764e8bf8f8da3a7a74fd7ddda172251530a830.png)

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

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [March 22, 2023, 7:10pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-tag-editor/71457/2 "2023-03-22T19:10:03Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/system.db.createSProcCall):

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/915029b4e4e3bc998d46fa65999a055af87b2578.png)

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

```python
system.db.execSProcCall(system.db.createSProcCall("sp_test", "<database_connection_name>"))

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 22, 2023, 7:46pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-tag-editor/71457/3 "2023-03-22T19:46:26Z")

</div>

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.
