# Error When Polling Data from SQL Queries

**URL:** <https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [July 31, 2024, 9:27am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958 "2024-07-31T09:27:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Puja\_Mallem](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@Puja\_Mallem](https://forum.inductiveautomation.com/u/Puja_Mallem)\
**Post date:** [July 31, 2024, 9:27am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958/1 "2024-07-31T09:27:58Z")

</div>

**I am encountering an error when trying to poll data from SQL queries in Ignition. This issue has arisen recently, and the queries were previously working fine without any problems.**  
java.lang.Exception: Error running query:  
SQLQuery(query=SELECT top(1) equipmentphase FROM Batch\_view\_table  
order by starttime desc, database=Chrom\_DB)@250ms  
On: SQL-OPC.Root Container.Label 2.text  
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$QueryExecutor.run(QueryManager.java:311)  
at java.base/java.lang.Thread.run(Unknown Source)  
Caused by: com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: Read timed out  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.newGatewayException(GatewayInterface.java:360)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.getResponse(GatewayInterface.java:556)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.sendMessage(GatewayInterface.java:292)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.sendMessage(GatewayInterface.java:287)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.runLimitQuery(GatewayInterface.java:893)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.runQuery(GatewayInterface.java:864)  
at com.inductiveautomation.factorypmi.application.gateway.SQLQuery.execute(SQLQuery.java:50)  
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$Query.execute(QueryManager.java:668)  
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$QueryExecutor.run(QueryManager.java:308)  
... 1 more  
Caused by: java.net.SocketTimeoutException: Read timed out  
at java.base/sun.nio.ch.NioSocketImpl.timedRead(Unknown Source)  
at java.base/sun.nio.ch.NioSocketImpl.implRead(Unknown Source)  
at java.base/sun.nio.ch.NioSocketImpl.read(Unknown Source)  
at java.base/sun.nio.ch.NioSocketImpl$1.read(Unknown Source)  
at java.base/java.net.Socket$SocketInputStream.read(Unknown Source)  
at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source)  
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source)  
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source)  
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(Unknown Source)  
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(Unknown Source)  
at java.base/java.io.BufferedInputStream.fill(Unknown Source)  
at java.base/java.io.BufferedInputStream.read1(Unknown Source)  
at java.base/java.io.BufferedInputStream.read(Unknown Source)  
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)  
at java.base/sun.net.www.http.HttpClient.parseHTTP(Unknown Source)  
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)  
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)  
at java.base/java.net.HttpURLConnection.getResponseCode(Unknown Source)  
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)  
at com.inductiveautomation.ignition.client.gateway\_interface.GatewayInterface.getResponse(GatewayInterface.java:450)  
... 8 more

Ignition v8.1.36 (b2024010211)  
Java: Azul Systems, Inc. 17.0.8

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [July 31, 2024, 10:28am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958/2 "2024-07-31T10:28:37Z")

</div>

Hi,

You might want to check the quality of the connection to your DB.

As the error message states, the query seems to time out.

Is the status of the DB Connection in the Gateway Valid ? Are there any other logs related to your SQL DB in the Gateway logs ?

---

<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:** [July 31, 2024, 11:57am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958/3 "2024-07-31T11:57:04Z")

</div>

Vision has a hard 60-second limit on responses from the gateway to the Vision client. Which breaks for queries that take more than 60 seconds. Something about your environment is making these queries take longer than they used to.

If these are history queries, and the tables involved are missing the correct indices, then queries will get slower as data accumulates.

---

<div class="post-metadata">

**Author:** ![Puja\_Mallem](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@Puja\_Mallem](https://forum.inductiveautomation.com/u/Puja_Mallem)\
**Post date:** [August 6, 2024, 6:39am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958/4 "2024-08-06T06:39:56Z")

</div>

I want to poll the SQL data as soon as the data is updated in the SQL rows. My query is  
SELECT TOP(1) BatchID, uniqueID, equipmentphase, starttime, endtime, completionstate, RecordID  
FROM Batch\_view\_table  
ORDER BY starttime DESC  
but it gives an error when I try to fetch data.

 ![mceclip0](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/20c9fecbc03fc8ed39bc9153b265d6a7bbde7f18.png)

---

<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:** [August 6, 2024, 11:10am UTC](https://forum.inductiveautomation.com/t/error-when-polling-data-from-sql-queries/93958/5 "2024-08-06T11:10:31Z")

</div>

Seems pretty clear to me. You don't have legacy database permissions enabled in your project. (And you shouldn't turn that on--use Named Queries instead.)
