暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MSSQL: Socket Closed 分析

晃荡萝卜DBs 2021-04-12
1492

查阅了一些资料,该问题发生的原因有很多种。

“socketclosed”错误表示连接已终止,但是未提供/返回任何特定原因。该错误表明连接意外终止。

 

可能有许多原因,例如:

-网络故障

-防火墙超时

-数据库意外终止了连接

-帐户权

 

 

Timeoutexpired”有可能是query执行的时间太长,超过了application指定的 timeout value。也有可能当时SQL server有一些性能问题,导致及时响应业务端的请求。

一方面,需要您那边提供相关的语句看看能否重现问题,我们看看能否优化语句。

另一方面,看看能否增加timeout的值。这个需要联系application做修改,如下是一个类似的地方。

 

SQL_ATTR_QUERY_TIMEOUT (ODBC 1.0)

An SQLULEN value corresponding to the number of seconds to  wait for an SQL statement to execute before returning to the application.  If ValuePtr is equal to 0 (default), there is no timeout.
 
 If the specified timeout exceeds the maximum timeout in the data source or is  smaller than the minimum timeout, SQLSetStmtAttr substitutes  that value and returns SQLSTATE 01S02 (Option value changed).
 
 Note that the application need not call SQLCloseCursor to  reuse the statement if a SELECT statement timed out.
 
 The query timeout set in this statement attribute is valid in both  synchronous and asynchronous modes.

 

https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetstmtattr-function?view=sql-server-ver15

 

 

基于上面的分析,有可能是网络原因,也有可能是query跑得太慢导致超时。从现有的信息,比较难做进一步的判断。

对于“socketclosed”,可能需要抓网络包进行分析。我们可以后台一直抓着网络包,问题发生后再停止。

对于“Timeoutexpired”,需要看看querysql server但是有没有性能的问题。

 

通常需进一步抓网络包,或者监控SQL server看看服务器的性能做进一步分析。

 


文章转载自晃荡萝卜DBs,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论