Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 实体框架在保存更改时出现间歇性超时_Sql Server_Entity Framework - Fatal编程技术网

Sql server 实体框架在保存更改时出现间歇性超时

Sql server 实体框架在保存更改时出现间歇性超时,sql-server,entity-framework,Sql Server,Entity Framework,我们在使用Entity Framework调用SaveChanges时遇到间歇性超时,我决定打开数据库.LogonDbContext尝试了解发生了什么,输出如下: 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, [

我们在使用Entity Framework调用
SaveChanges
时遇到间歇性超时,我决定打开
数据库.Log
on
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秒,这比我们的超时限制要小


有人知道为什么我们会间歇性地收到这些信息吗?

我不能肯定,但您的服务器似乎使用的可用内存非常少。以下事项之一可能适用于您-

  • 增加一次较大值的超时。当查询第二次运行时,可能不会花费太多时间,因为它已经有了执行计划
  • 删除事务日志、tempDb数据

  • 在查询中使用筛选条件一次更新较小的数据集


  • 您正在使用TransactionScope吗?没有事务Scope。需要查看代码才能知道发生了什么。