# runQuery on MSSql

**URL:** <https://forum.inductiveautomation.com/t/runquery-on-mssql/14280>\
**Category:** Ignition\
**Created:** [May 12, 2017, 6:38pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280 "2017-05-12T18:38:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adolfo.rafael.martin](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@adolfo.rafael.martin](https://forum.inductiveautomation.com/u/adolfo.rafael.martin)\
**Post date:** [May 12, 2017, 6:38pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/1 "2017-05-12T18:38:48Z")

</div>

In a WebDev Python script I have tried

alarmEvents = system.db.runQuery(“select \* from alarm\_events”)

and

alarmEvents = system.db.runQuery(“select \* from dbo.alarm\_events”)

but i get

at java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runQuery(select \* from dbo.alarm\_events, , )  
…  
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 30, in doGet

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 12, 2017, 7:29pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/2 "2017-05-12T19:29:32Z")

</div>

Can you post the full error stacktrace?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 12, 2017, 8:43pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/4 "2017-05-12T20:43:04Z")

</div>

It’s almost certainly what @KathyApplebaum mentioned; because WebDev resources run in the gateway scope, there is no ‘default’ datasource to use - so the script will error out. Pass in the DB name as the second argument to runQuery, eg:

```auto
system.db.runQuery("SELECT * FROM SOME_TABLE", "DB")

```

And your script will likely work correctly.

---

<div class="post-metadata">

**Author:** ![adolfo.rafael.martin](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@adolfo.rafael.martin](https://forum.inductiveautomation.com/u/adolfo.rafael.martin)\
**Post date:** [May 15, 2017, 2:43pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/5 "2017-05-15T14:43:51Z")

</div>

Added “DB” e.g.

```
alarmEvents = system.db.runQuery("select * from dbo.alarm_events", "DB")

```

But still got error e.g.

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 30, in doGet  
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:364)  
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runQuery(AbstractDBUtilities.java:335)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
at java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runQuery(select \* from dbo.alarm\_events, DB, )

Any suggestions appreciated.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [May 15, 2017, 3:27pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/6 "2017-05-15T15:27:10Z")

</div>

Is that the full stacktrace? If not, then please post the full stack trace. Sometimes the full stack trace indicates what is wrong.

---

<div class="post-metadata">

**Author:** ![Brian\_F](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@Brian\_F](https://forum.inductiveautomation.com/u/Brian_F)\
**Post date:** [May 15, 2017, 7:22pm UTC](https://forum.inductiveautomation.com/t/runquery-on-mssql/14280/7 "2017-05-15T19:22:31Z")

</div>

With MS SQL I have had problems referencing table and field names without surrounding them in square brackets.  
Have you tried “SELECT \* FROM [alarm\_events]”?
