# Use runPrepQuery not in the default database, but result shows the database is not defined

**URL:** <https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [February 8, 2023, 2:28am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565 "2023-02-08T02:28:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ziming\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/53a042/32.png) [@Ziming\_Wang](https://forum.inductiveautomation.com/u/Ziming_Wang)\
**Post date:** [February 8, 2023, 2:28am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/1 "2023-02-08T02:28:43Z")

</div>

I try to download the file from the database, but not from the default database. The new database called SmartOpsAU. When I use the runPrepQuery, the result show the new database is not defined.

**system.db.runPrepQuery(query, args, [database], [tx])**

```auto
	id = self.view.params.post[0].fileid

	query = "select filename,attachment from postfile where id =?"
	args = [id]
	data = system.db.runPrepQuery (query, args, [SmartOpsAU])

	filename = data[0][0]
	attachment = data[0][1]

   	system.prespective.download(filename,attachment)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/56eda0d0a86b4509cde0d8709dd07ff71c824328.png)

Thanks for help

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [February 8, 2023, 3:08am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/2 "2023-02-08T03:08:00Z")

</div>

The database argument in system.db.runPrepQuery is the name of the database _connection_. Your database connections are set up on the gateway under Config \> Databases \> Connections. If SmartOpsAU is a new database you will need to setup a connection for it.

---

<div class="post-metadata">

**Author:** ![Ziming\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/53a042/32.png) [@Ziming\_Wang](https://forum.inductiveautomation.com/u/Ziming_Wang)\
**Post date:** [February 8, 2023, 3:24am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/3 "2023-02-08T03:24:32Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e6a2f3e3944a42a48714a4d131e41f67c635e055.png)  
Thanks for reply, the new database have been connected.

---

<div class="post-metadata">

**Author:** ![amy.sudibyo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amy.sudibyo/32/38659_2.png) [@amy.sudibyo](https://forum.inductiveautomation.com/u/amy.sudibyo)\
**Post date:** [February 8, 2023, 3:30am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/4 "2023-02-08T03:30:50Z")

</div>

I've just re-read your original post and noticed a couple more things:

- you have put the database in square brackets, which is not the correct syntax. The square brackets around the parameter in the function name denote that the parameter is optional
- you have not enclosed SmartOpsAU in quotation marks to indicate that it is a string value, not a variable name

---

<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:** [February 8, 2023, 9:33am UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/5 "2023-02-08T09:33:06Z")

</div>

Amy gave you the solution, but there's something else that's worth mentioning.

The error message doesn't say that the database is not defined, it says that the `SmartOpsAu` variable is not defined. Error messages like that are VERY useful for debugging, pay attention to what they say and more often than not they'll give you the answers you're looking for.

---

<div class="post-metadata">

**Author:** ![Ziming\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/53a042/32.png) [@Ziming\_Wang](https://forum.inductiveautomation.com/u/Ziming_Wang)\
**Post date:** [February 8, 2023, 11:52pm UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/6 "2023-02-08T23:52:55Z")

</div>

Thanks Amy, have been solved.

---

<div class="post-metadata">

**Author:** ![Ziming\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/53a042/32.png) [@Ziming\_Wang](https://forum.inductiveautomation.com/u/Ziming_Wang)\
**Post date:** [February 8, 2023, 11:53pm UTC](https://forum.inductiveautomation.com/t/use-runprepquery-not-in-the-default-database-but-result-shows-the-database-is-not-defined/69565/7 "2023-02-08T23:53:12Z")

</div>

Thanks for advice.
