# Database Source Not Found

**URL:** <https://forum.inductiveautomation.com/t/database-source-not-found/84551>\
**Category:** Ignition\
**Tags:** database, perspective, scripting\
**Created:** [January 22, 2024, 5:34am UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551 "2024-01-22T05:34:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 22, 2024, 5:34am UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/1 "2024-01-22T05:34:55Z")

</div>

I have been breaking my head over this for a couple of hours now and I can't figure out what is wrong with this I am trying to make a simple db update query but I keep getting an error everytime I run it this is the script:

```auto
def runAction(self, event):
	# Define the query with placeholders
	queryName = "UPDATE levelChecker SET width = '5.6' WHERE IDValue = 'A55638U89'"
	
	# Define the arguments as a list
	#args = [self.view.params.Value]
	
	databaseName = "DBSecondaryConnection"
	
	# Run the query and get the number of rows affected
	rows = system.db.runUpdateQuery(query = queryName, database = databaseName, tx = 5000)

```

and here is the error:

```auto
	Error running action 'dom.onClick' on screens/popups/databaseEditorPopup@6n8lW90/root/FlexContainer_0/Button: Traceback (most recent call last): File "<function:runAction>", line 11, in runAction at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runUpdateQuery(AbstractDBUtilities.java:188) 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.runUpdateQuery(UPDATE levelChecker SET width = '5.6' WHERE IDValue = 'A55638U89', Transaction datasource unknown, 5000, false)

```

I looked up the error and it is saying it is related to the fact that the database connection doesn't exist. But I doublechecked the name and even did a script to get the name of it. i am also pulling information and inputting information to it from transaction groups and tag queries. I am doing in it scripting because eventually this script needs be dynamic where the table name, column and IDValue change. Anyone have any ideas on why this isn't working?

---

<div class="post-metadata">

**Author:** ![MSviga](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MSviga](https://forum.inductiveautomation.com/u/MSviga)\
**Post date:** [January 22, 2024, 6:55am UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/2 "2024-01-22T06:55:36Z")

</div>

Consider setting up a Named Query. They allow you to specify the database connection and tests the query aswell. The its as simple as running the `system.db.runNamedQuery()` function.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 22, 2024, 10:24am UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/3 "2024-01-22T10:24:00Z")

</div>

You're providing a `tx`, which expects a transaction id. Where does it come from ? you're passing `5000`, which doesn't look like a transaction id to me, more like a timeout delay.

If you did mean to supply a transaction id, make sure it's correct and the transaction is opened.  
Otherwise, remove that parameter.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 22, 2024, 1:38pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/4 "2024-01-22T13:38:16Z")

</div>

I addition to what @pascal.fragnoud said, if for whatever reason you don't want to use a named query, and instead wish to do it all in script, then you should be using `system.db.runPrepUpdate()` that would look like this:

```python
def runAction(self,event):
    query = 'UPDATE levelChecker SET width = ? WHERE IDValue = ?'
    args = [5.6,'A55638u89']
    databaseName = 'DBSecondaryConnection'
    system.db.runPrepUpdate(query,args,databaseName)

```

---

<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:** [January 22, 2024, 1:44pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/5 "2024-01-22T13:44:56Z")

</div>

Side note: Many older IA functions do not accept keyword arguments, or don't accept them for the mandatory args. (`system.db.runUpdateQuery` is a very old function.) Newer functions have full support for keyword arguments, and usually **say so** in the documentation.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 22, 2024, 2:01pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/6 "2024-01-22T14:01:19Z")

</div>

Correct me if I am wrong, but you have specified the DB name, but aren't actually calling it in the system.db call?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 22, 2024, 2:02pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/7 "2024-01-22T14:02:33Z")

</div>

Nope, not wrong. Corrected code.

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 22, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/8 "2024-01-22T15:45:43Z")

</div>

Ok that seemed to work thank you. However, this brings me to my next issue I want to be able to dynamically pass the column name as well. I changed my code to this but I don't get an error thrown but it also doesn't pass the update to the db:

```auto
    query = 'UPDATE levelChecker SET ? = ? WHERE IDValue = ?'
    args = [self.view.params.Column, self.getSibling("NumericEntryField").props.value, self.view.params.DPIN]
    databaseName = 'DBSecondaryConnection'
    system.db.runPrepUpdate(query,args,databaseName)

```

---

<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:** [January 22, 2024, 3:56pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/9 "2024-01-22T15:56:19Z")

</div>

Column names aren't values. In SQL, they are part of a query's _structure_, which is used to prepare the execution plan. So they have to be injected into the query string itself, not passed as a parameter. Because of the high risk associated with this, you should always check such a string substitution against the known column names for a table. (Get them from your DB's `information_schema` if you want to automate it.)

---

<div class="post-metadata">

**Author:** ![scadafan](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@scadafan](https://forum.inductiveautomation.com/u/scadafan)\
**Post date:** [January 22, 2024, 7:31pm UTC](https://forum.inductiveautomation.com/t/database-source-not-found/84551/10 "2024-01-22T19:31:23Z")

</div>

Yes. That makes sense I had forgotten about that. Everything is working now as expected. Thank you everyone's help!
