# Calling a stored procedure in MS SQL using the system.db.execSProcCall(call)

**URL:** <https://forum.inductiveautomation.com/t/calling-a-stored-procedure-in-ms-sql-using-the-system-db-execsproccall-call/41736>\
**Category:** Ignition\
**Tags:** perspective, ignition80\
**Created:** [December 22, 2020, 8:39pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-in-ms-sql-using-the-system-db-execsproccall-call/41736 "2020-12-22T20:39:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nidal](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@Nidal](https://forum.inductiveautomation.com/u/Nidal)\
**Post date:** [December 22, 2020, 8:39pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-in-ms-sql-using-the-system-db-execsproccall-call/41736/1 "2020-12-22T20:39:05Z")

</div>

I have a stored procedure in MSSQL as shown below:

ALTER PROCEDURE [dbo].[ca\_qry\_Carton\_SCADA]  
@p\_CartonNo varchar(50) ,  
@p\_SealerFlag INT OUTPUT ,  
@p\_PalletStationNo INT OUTPUT  
AS

In Ignition I have a script that calls the procedure but I get a strange error when I try to register the input parameter which is a string (VARCHAR). Ignition script is shown below:

call = system.db.createSProcCall("[dbo].[ca\_qry\_Carton\_SCADA]",‘ABC\_Packer\_Rockit\_Database’)  
call.registerReturnParam(system.db.INTEGER)  
call.registerInParam("@p\_CartonNo", system.db.VARCHAR, mystring)  
call.registerOutParam("@p\_SealerFlag", system.db.INTEGER)  
call.registerOutParam("@p\_PalletStationNo", system.db.INTEGER)

system.db.execSProcCall(call)

mystring is a predefined tag with datatype string and a value of “NJK746”

When I run this script in the script console it fails and shows the following error:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the varchar value ‘N’ to data type int.

I don’t understand why it is attempting to convert a string to integer on line 3 (registerInParam)??!! Am I missing something?

below is the full error information:

Java Traceback:  
Traceback (most recent call last):  
File “”, line 19, in   
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)  
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(AbstractDBUtilities.java:497)  
at jdk.internal.reflect.GeneratedMethodAccessor150.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()

```
at org.python.core.Py.JavaError(Py.java:552)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(AbstractDBUtilities.java:497)
at jdk.internal.reflect.GeneratedMethodAccessor150.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:188)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:523)
at org.python.core.PyObject. __call__ (PyObject.java:480)
at org.python.core.PyObject. __call__ (PyObject.java:484)
at org.python.pycode._pyx433.f$0(<input>:28)
at org.python.pycode._pyx433.call_function(<input>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)
at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

```

Caused by: java.lang.Exception: Error executing system.db.execSProcCall()  
… 25 more  
Caused by: com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: Conversion failed when converting the varchar value ‘N’ to data type int.  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.newGatewayException(GatewayInterface.java:359)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.sendMessage(GatewayInterface.java:333)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.sendMessage(GatewayInterface.java:286)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.invoke(GatewayInterface.java:942)  
at com.inductiveautomation.ignition.client.script.ClientDBUtilities.\_call(ClientDBUtilities.java:345)  
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(AbstractDBUtilities.java:495)  
… 23 more  
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the varchar value ‘N’ to data type int.  
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:256)  
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1621)  
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:592)  
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:522)  
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)  
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2930)  
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)  
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)  
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:503)  
at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)  
at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)  
at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.execute(SRConnectionWrapper.java:996)  
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.\_callSProc(GatewayDBUtilities.java:310)  
at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.CallSProc.call(CallSProc.java:42)  
at jdk.internal.reflect.GeneratedMethodAccessor146.invoke(null)  
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(null)  
at java.lang.reflect.Method.invoke(null)  
at com.inductiveautomation.ignition.gateway.servlets.gateway.AbstractGatewayFunction.invoke(AbstractGatewayFunction.java:225)  
at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:405)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)  
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)  
at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)  
at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1391)  
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:760)  
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)  
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)  
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:590)  
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)  
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)  
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607)  
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)  
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)  
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)  
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)  
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577)  
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)  
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)  
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)  
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)  
at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)  
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59)  
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)  
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)  
at org.eclipse.jetty.server.Server.handle(Server.java:500)  
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)  
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)  
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)  
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)  
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)  
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)  
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)  
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)  
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)  
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)  
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)  
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:388)  
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)  
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)  
at java.lang.Thread.run(null)  
Traceback (most recent call last):  
File “”, line 19, in   
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)  
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.execSProcCall(AbstractDBUtilities.java:497)  
at jdk.internal.reflect.GeneratedMethodAccessor150.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:** ![Nidal](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@Nidal](https://forum.inductiveautomation.com/u/Nidal)\
**Post date:** [December 22, 2020, 8:44pm UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-in-ms-sql-using-the-system-db-execsproccall-call/41736/2 "2020-12-22T20:44:01Z")

</div>

If I change mystring value to contain only numbers and no letters then the script runs fine.

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [December 23, 2020, 3:17am UTC](https://forum.inductiveautomation.com/t/calling-a-stored-procedure-in-ms-sql-using-the-system-db-execsproccall-call/41736/3 "2020-12-23T03:17:50Z")

</div>

I’m wondering if this is perhaps something occurring to generate an exception within your Stored Procedure itself? I spooled up a test with basic stored proc contents as below:

```sql
ALTER PROCEDURE ca_qry_Carton_SCADA 
	@p_CartonNo varchar(50) ,
	@p_SealerFlag INT OUTPUT ,
	@p_PalletStationNo INT OUTPUT
AS
BEGIN
	SET NOCOUNT ON;

	-- Example Result Set
	SELECT @p_CartonNo as [Carton Number]

	-- Example setting of output parameters
	SET @p_SealerFlag=1
	SET @p_PalletStationNo=2
END
GO

```

Running the stored procedure seems to function as expected:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/9/49e41001a197274f19d38687c644019f4eb5f6c8.png)

My test was conducted against MSSQL 2019 and Ignition 8.1.1.
