# Script Error:-system.db.runPrepUpdate Cant connect to different database than to project default database?

**URL:** <https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135>\
**Category:** Ignition\
**Created:** [May 19, 2019, 4:39pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135 "2019-05-19T16:39:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 19, 2019, 4:39pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/1 "2019-05-19T16:39:30Z")

</div>

Can any one help me to understand the syntax error that i am using in this script  
Action performed Execution error that the ignitionhistorydb.prddp' doesn't exist

**database connection named as db and connected URL to database called production**  
**Project default database is ingtionhistorydb.**  
**prdp is a table of production database**

> Shift=event.source.parent.getComponent('Shift').selectedValue  
> Product=event.source.parent.getComponent('ProductList').selectedStringValue  
> Qty=event.source.parent.getComponent('Qty').intValue  
> IdPrdDP=201983245
> 
> txID=system.db.beginTransaction()  
> system.db.runPrepUpdate("INSERT INTO prddp (Shift, Product, Qty, IdPrdDP) VALUES (?,?,?,?)", [Shift,Product,Qty,IdPrdDP])  
> system.db.commitTransaction(txID)  
> system.db.closeTransaction(txID)  
> '

'Traceback (most recent call last):

File "event:actionPerformed", line 7, in

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO prddp (Shift, Product, Qty, IdPrdDP) VALUES (?,?,?,?), [3, PRD-A, 231, 201983245], , , false, false)

```
caused by Exception: Error executing system.db.runPrepUpdate(INSERT INTO prddp (Shift, Product, Qty, IdPrdDP) VALUES (?,?,?,?), [3, PRD-A, 231, 201983245], , , false, false)
caused by GatewayException: SQL error for "INSERT INTO prddp (Shift, Product, Qty, IdPrdDP) VALUES (?,?,?,?)": Table 'ignitionhistorydb.prddp' doesn't exist
caused by SQLSyntaxErrorException: Table 'ignitionhistorydb.prddp' doesn't exist

```

Ignition v7.5.14 (b1594)  
Java: Oracle Corporation 1.8.0\_211  
'

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [May 19, 2019, 8:11pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/2 "2019-05-19T20:11:44Z")

</div>

> [@shibubalaji](#):
>
> txID=system.db.beginTransaction()

txID=system.db.beginTransaction(database="production")

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 19, 2019, 8:53pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/3 "2019-05-19T20:53:24Z")

</div>

Jpart,  
Thanks for your response and I did the same as you said , but now the error looks like below.

"Traceback (most recent call last):

File “event:actionPerformed”, line 7, in

java.lang.Exception: java.lang.Exception: Error executing system.db.beginTransaction(production, 2, 30000)

```
caused by Exception: Error executing system.db.beginTransaction(production, 2, 30000)
caused by GatewayException: Datasource "production" does not exist in this Gateway.
caused by SQLException: Datasource "production" does not exist in this Gateway.

```

Ignition v7.5.14 (b1594)  
Java: Oracle Corporation 1.8.0\_211

"

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [May 19, 2019, 9:21pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/4 "2019-05-19T21:21:29Z")

</div>

```auto
txID=system.db.beginTransaction(database = "IGNITION DATABASE CONNECTION NAME HERE")
system.db.runPrepUpdate(“INSERT INTO prddp (Shift, Product, Qty, IdPrdDP) VALUES (?,?,?,?)”, [Shift,Product,Qty,IdPrdDP], tx = txID)
system.db.commitTransaction(txID)
system.db.closeTransaction(txID)

```

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 20, 2019, 1:04am UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/5 "2019-05-20T01:04:31Z")

</div>

J, Thanks for the help and is working fine…Great. job!

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 23, 2019, 4:34pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/6 "2019-05-23T16:34:01Z")

</div>

J,  
Would help me to understand what is wrong in this first syntax?  
Cant we use argument and parameters runScalarQuery?

> Blockquote

system.db.runScalarQuery("SELECT idproductList FROM productlist WHERE productList = (?)",[Product],tx=txID1)  
_Result# QLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?)' at line 1_

* * *

* * *

system.db.runScalarQuery("SELECT idproductList FROM productlist WHERE productList = 'PRD-A',tx=txID1)

_Result# 10 ,_ which is correct

> Blockquote

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 23, 2019, 5:35pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/7 "2019-05-23T17:35:51Z")

</div>

> [@shibubalaji](#):
>
> Cant we use argument and parameters runScalarQuery?

No, you cannot. But there's [system.db.runScalarPrepQuery()](https://docs.inductiveautomation.com/display/DOC79/system.db.runScalarPrepQuery) for that.

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 24, 2019, 4:15pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/8 "2019-05-24T16:15:56Z")

</div>

Phil, Thanks of the response.  
But is that not available on 7.5? Also, I dont see any examples under 7.8 knowledge base ([system.db.runScalarPrepQuery - Ignition User Manual 7.8 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC/system.db.runScalarPrepQuery))  
Is that some thing new on 7.9?  
I get an error on 7.5  
AttributeError: 'com.inductiveautomation.ignition.common.script.Scr' object has no attribute 'runScalarPrepQuery'

> Blockquote

Product = event.source.parent.getComponent("ProductList").selectedStringValue  
system.db.runScalarPrepQuery("SELECT productlist FROM idproductlist WHERE idproductList = ?", [Product])

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 24, 2019, 4:37pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/9 "2019-05-24T16:37:36Z")

</div>

> [@shibubalaji](#):
>
> But is that not available on 7.5?

Ah, sorry. Missed that you are using v7.5. My advice would be to upgrade to a supported version.... /-:

---

<div class="post-metadata">

**Author:** ![shibubalaji](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shibubalaji/32/9165_2.png) [@shibubalaji](https://forum.inductiveautomation.com/u/shibubalaji)\
**Post date:** [May 24, 2019, 5:28pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/10 "2019-05-24T17:28:55Z")

</div>

> [@shibubalaji](#):
>
> corresponds to your MySQL server version for the right syntax to use near ‘?)

Phil 8.0 has Namedquery and is much easier on that.

---

<div class="post-metadata">

**Author:** ![Subbarao.B](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Subbarao.B](https://forum.inductiveautomation.com/u/Subbarao.B)\
**Post date:** [October 22, 2021, 2:05pm UTC](https://forum.inductiveautomation.com/t/script-error-system-db-runprepupdate-cant-connect-to-different-database-than-to-project-default-database/25135/11 "2021-10-22T14:05:31Z")

</div>

if transaction is aborted, then i need to record that data into some table .  
or  
Need to open a pop up and display that to corresponding Operator.

how to do that.
