The exception was thrown at this line of code
dynamic result = connection.Query(RetrieveTime).SingleOrDefault();
retrievetime is a query which looks like this
private const string RetrieveTime = @"SELECT TOP (1) (LocalTime)
From (
SELECT (LocalTime)
From iot.DeviceMessage
Union All
SELECT (LocalTime)
From iot.DeviceMessageHistory
Where Not Exists (Select 1 From iot.DeviceMessage)
) X
Order By (LocalTime) desc";
Here is the full error message:
Error: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
Because your query string run very slowly. You could improve your query to faster. Probably, with your query, I think you want get max LocalTime in DeviceMessage and DeviceMessageHistory table. So you could try this query:
SELECT TOP (1) (LocalTime)
FROM
(
SELECT TOP 1 LocalTime FROM iot.DeviceMessage Order By (LocalTime) desc
Union All
SELECT TOP 1 LocalTime FROM iot.DeviceMessageHistory Order By (LocalTime) desc
)
AS DATA
Order By (LocalTime) desc
User contributions licensed under CC BY-SA 3.0