SqlException timeout expired without being reached

本小妞迷上赌 提交于 2019-12-05 23:14:29
Whaaag

In fact we still experienced these random timeouts even after READ_COMMITED_SNAPSHOT was set.

Setting the mirror in asynchronous mode didn't helped, queries done in multiple threads still randomly timeouted after about 1ms, always on busy periods. On the other hand the specific query that triggered the timeout (an INSERT statement) executed itself really fast (less than 1ms CPU and about 10 reads in average).

The call stack was the following:

at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)

at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

at System.Data.SqlClient.SqlConnection.Open()

So the timeout didn't seem related to the query itself.

According to this other post : Multiple Simultaneous SQL Connection Timeouts In Multithreaded Windows Service and the linked MSDN blog post speaking about an ADO.NET bug, we tried to set the connection timeout to 150 in the connection string.

Can't be certain we were experiencing this bug, but no more timeouts have been thrown since this change.

In the end, after hours of tracking and profiling, the issue was the correlation of two things:

  1. Read committed default Sql Server isolation level leading to blocking situations
  2. Some really badly tuned requests and stored procedures mixed with indexless tables

The first cause was fixed with

ALTER DATABASE <dbName> SET READ_COMMITTED_SNAPSHOT ON

The second with lucid requests rewriting and table indexing.

I would run SQL Profiler at this point and see what queries are being executed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!