我们在使用Entity Framework调用SaveChanges
时遇到间歇性超时,我决定打开Database.Log
上的DbContext
来尝试找出正在发生的事情,输出结果是如下:
Opened connection at 5/9/2015 4:56:57 PM +00:00
Started transaction at 5/9/2015 4:56:57 PM +00:00
UPDATE [Search].[IndexingStatuses]
SET [DateTimeLastUpdated] = @0, [IndexStores_IndexStoreId] = @1
WHERE ([CustomerId] = @2)
-- @0: '5/9/2015 4:03:57 PM' (Type = DateTime2)
-- @1: '2' (Type = Int16)
-- @2: '1' (Type = Int32)
-- Executing at 5/9/2015 4:56:57 PM +00:00
-- Completed in 1 ms with result: 1
Failed to commit transaction at 5/9/2015 4:57:13 PM +00:00 with error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Closed connection at 5/9/2015 4:57:13 PM +00:00
这很奇怪,这是一个简单的更新,你可以看到事务在4:56:57开始,更新需要1毫秒,但由于某种原因,在4:57:13有一个超时,这只是16秒后,无论如何都低于我们的超时限制。
有谁知道为什么我们间歇地得到这些?
答案 0 :(得分:0)
我不能肯定地说,但似乎你的服务器运行的内存非常少。以下其中一项可能对您有用 -
删除事务日志,tempDb数据。
在查询中使用过滤条件,一次更新较小的数据集。