# \[bug: IGN-2494\] runSFNamedQuery Error:GatewayNamedQueryManager

**URL:** <https://forum.inductiveautomation.com/t/bug-ign-2494-runsfnamedquery-error-gatewaynamedquerymanager/47745>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [June 14, 2021, 2:03pm UTC](https://forum.inductiveautomation.com/t/bug-ign-2494-runsfnamedquery-error-gatewaynamedquerymanager/47745 "2021-06-14T14:03:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.lebohec](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/r.lebohec/32/3704_2.png) [@r.lebohec](https://forum.inductiveautomation.com/u/r.lebohec)\
**Post date:** [June 14, 2021, 2:03pm UTC](https://forum.inductiveautomation.com/t/bug-ign-2494-runsfnamedquery-error-gatewaynamedquerymanager/47745/1 "2021-06-14T14:03:53Z")

</div>

As the Ignition documentation indicates, i want to use the 'system.db.runSFNamedQuery' function in a Gateway script to do an insert to 2 differents databases.  
This function doesn't succeed when 'database'/'datasource' is a define as a parameter of namedquery

> INFO | jvm 1 | 2021/06/14 15:58:34 | I [G.GTC\_Lapi] [13:58:33]: Fct: 'shared.commun.lapi.manager.insertDBVehicule' Message: 'results[0] id:[1623679113] project:[TMB\_GTC\_AIRE\_PASSY] , params:[{'idtmd': 1623679113L, 'dateend': Mon Jun 14 15:58:33 CEST 2021, 'idhg': 1623679113L, 'datestart': Mon Jun 14 15:58:33 CEST 2021, 'numvoie': 2, 'database': 'histo\_lapi', 'id': 1623679113L, 'idlog': 1623679113L, 'numzone': 1}], pathQuery:[lapi/insertVehicule]' store-forward-name={}, byes-script=GTC\_Lapi  
> INFO | jvm 1 | 2021/06/14 15:58:34 | E [GatewayNamedQueryManager] [13:58:33]: Could not store history for datasource '{}' for query INSERT INTO hg(  
> INFO | jvm 1 | 2021/06/14 15:58:34 | id,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | class,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | width,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | height)VALUES(  
> INFO | jvm 1 | 2021/06/14 15:58:34 | :id,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | :class ,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | :width,  
> INFO | jvm 1 | 2021/06/14 15:58:34 | :height )  
> INFO | jvm 1 | 2021/06/14 15:58:34 | . store-forward-name={}  
> INFO | jvm 1 | 2021/06/14 15:58:34 | java.lang.IllegalArgumentException: Specified historical sink '{}' does not exist.  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.history.HistoryManagerImpl.storeHistory(HistoryManagerImpl.java:207)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.db.namedquery.GatewayNamedQueryManager.executeSFquery(GatewayNamedQueryManager.java:179)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runSFNamedQuery(GatewayDBUtilities.java:422)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.lang.reflect.Method.invoke(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:188)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. **call** (ScriptManager.java:538)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyObject. **call** (PyObject.java:413)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode._pyx341.insertDBVehicule$12(module:shared.commun.lapi.manager:463)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode.pyx341.call\_function(module:shared.commun.lapi.manager)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyTableCode.call(PyTableCode.java:171)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyBaseCode.call(PyBaseCode.java:308)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction.function\_\_\_call_(PyFunction.java:471)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction. **call** (PyFunction.java:466)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode.\_pyx341.tests$13(module:shared.commun.lapi.manager:492)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode.\_pyx341.call\_function(module:shared.commun.lapi.manager)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyTableCode.call(PyTableCode.java:171)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyBaseCode.call(PyBaseCode.java:125)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction. **call** (PyFunction.java:403)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode._pyx363.valueChanged$1(tagevent:valueChanged:6)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.pycode.pyx363.call\_function(tagevent:valueChanged)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyTableCode.call(PyTableCode.java:171)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyBaseCode.call(PyBaseCode.java:308)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction.function\_\_\_call_(PyFunction.java:471)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction. **call** (PyFunction.java:466)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at org.python.core.PyFunction. **call** (PyFunction.java:461)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:836)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:820)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:687)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$FunctionInvokerImpl.run(TagScriptManagerImpl.java:530)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.tags.scripting.events.AbstractTagScript.invoke(AbstractTagScript.java:34)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$Task.invoke(TagScriptManagerImpl.java:479)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.gateway.tags.scripting.TagScriptManagerImpl$TagScriptDispatcher.run(TagScriptManagerImpl.java:442)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:538)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.util.concurrent.FutureTask.run(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
> INFO | jvm 1 | 2021/06/14 15:58:34 | at java.base/java.lang.Thread.run(Unknown Source)

> Blockquote

```auto
def insertDBVehicule(id=None,dictParams={},datasources=[],project = ""):
	"""Fonction d'insertion en base de données via le SF d'un vehicule"""
	
	global INSERT_VEHICULE_QUERIES,DATASOURCES,LIB
	
	FCT = "insertDBVehicule"
	
	if id == None:
		#PK des enregistrements
		dtNow = system.date.now()
		msNow = system.date.toMillis(dtNow)/1000
		
	if project == "":
		import shared.commun.constantes
		project = shared.commun.constantes.getProject()
	
	if datasources == []:
		datasources = DATASOURCES.values()
		
	shared.commun.logger.logINFO(strMsg="Parameters id:[%d] project:[%s] datasources:[%s] dictParams:[%s]"%(id,project,str(datasources),str(dictParams)),strFct=FCT,strLib=LIB,dicoTrace={},strLog="GTC_Lapi")
		
	for type,params in dictParams.items():
		for datasource in datasources:
			#DANS chaque DS
			params['database']=datasource
			#params['datasource']=datasource
			
			params['id'] = id #Cle primaire de tous les enregistrements
			try:
				#result = system.db.runNamedQuery(project=project,path=INSERT_VEHICULE_QUERIES[type],parameters=params)
				result = system.db.runSFNamedQuery(project=project,path=INSERT_VEHICULE_QUERIES[type],params=params)
			except:
				shared.commun.logger.logERROR(strMsg="ERROR",strFct=FCT,strLib=LIB,dicoTrace={},strLog="GTC_Lapi")
			shared.commun.logger.logINFO(strMsg="results[%d] id:[%d] project:[%s] , params:[%s], pathQuery:[%s]"%(result,id,project,params,INSERT_VEHICULE_QUERIES[type]),strFct=FCT,strLib=LIB,dicoTrace={},strLog="GTC_Lapi")
				

```

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 14, 2021, 2:58pm UTC](https://forum.inductiveautomation.com/t/bug-ign-2494-runsfnamedquery-error-gatewaynamedquerymanager/47745/2 "2021-06-14T14:58:31Z")

</div>

This has been fixed in 8.1.8 and is available now in the nightlies.
