# Help with calling a stored procedure with a button in perspective

**URL:** <https://forum.inductiveautomation.com/t/help-with-calling-a-stored-procedure-with-a-button-in-perspective/97550>\
**Category:** Ignition\
**Tags:** database, perspective, scripting\
**Created:** [October 21, 2024, 3:30pm UTC](https://forum.inductiveautomation.com/t/help-with-calling-a-stored-procedure-with-a-button-in-perspective/97550 "2024-10-21T15:30:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Lerette](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@Jeffrey\_Lerette](https://forum.inductiveautomation.com/u/Jeffrey_Lerette)\
**Post date:** [October 21, 2024, 3:30pm UTC](https://forum.inductiveautomation.com/t/help-with-calling-a-stored-procedure-with-a-button-in-perspective/97550/1 "2024-10-21T15:30:40Z")

</div>

I am trying to use this script

```python
def runAction(self, event):
    SPcall = system.db.createSProcCall("BadgeAccess","Ignition")      
    SPcall.registerReturnParam(system.db.INTEGER)
    input1 = self.view.custom.testAccess.user
    input2 = self.view.custom.testAccess.machine
    SPcall.registerInParam("user", system.db.INTEGER, input1)
    SPcall.registerInParam("machine", system.db.INTEGER, input2)
    system.db.execSProcCall(SPcall)
    accessLevel = SPcall.getReturnValue()
    displayString = "User {self.view.custom.testAccess.user} logged into machine {self.view.custom.testAccess.machine} with level {accessLevel} access"
    self.view.custom.testAccess.displayString = displayString
    # Print the result to the console
    print(displayString)

```

To call a SP I have in my database. The SP runs fine on the database and has 2 inputs as INT's and an output as an INT. I would rather not have to hard type the query in Ignition and would rather run it as a SP since there is also logging occurring for this.

This is the error I am getting.  
Error running action 'component.onActionPerformed' on MachineAccess/main@D/root/FlexContainer/FlexContainer/Button: Traceback (most recent call last): File "function:runAction", line 8, in runAction 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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.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()

---

<div class="post-metadata">

**Author:** ![flexware](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/flexware/32/66243_2.png) [@flexware](https://forum.inductiveautomation.com/u/flexware)\
**Post date:** [October 22, 2024, 6:00pm UTC](https://forum.inductiveautomation.com/t/help-with-calling-a-stored-procedure-with-a-button-in-perspective/97550/3 "2024-10-22T18:00:42Z")

</div>

What database are you using (e.g. MySQL, MSSQL, Postgres)? Usually, what we found works well enough is to create a named query and then do something like

```sql
EXEC dbo.myBadgeAccess :user, :machine

```

and if you're expecting a single value as a return, set the Query Type to Scalar Query.
