简体   繁体   English

System.Data.SqlClient.SqlException:'执行超时已过期

[英]System.Data.SqlClient.SqlException: 'Execution Timeout Expired

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. System.Data.SqlClient.SqlException (0x80131904):执行超时已过期。 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 ---> System.ComponentModel.Win32Exception (0x80004005): 等待操作超时

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.可能,通过您的查询,我认为您希望在 DeviceMessage 和 DeviceMessageHistory 表中获得最大 LocalTime。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM