我们有一个 C# 多线程(100 个线程)程序,它从数据库中读取记录,每个线程获取一条记录(每个线程一个实体框架连接)并更新单个数据库表。
前几分钟(5 分钟)程序正常运行,然后突然所有线程开始抛出以下错误消息.. 约 1 分钟后,一切都会恢复正常阶段.. 我认为 SQL Server 也越来越好了单个数据库表的许多锁(可能正在尝试获取该表上的表锁)或与单个数据库的连接过多并关闭所有连接..
我无法调试这个,有人可以帮助我获取以下信息,
SQL Server 2012 在哪里存储其日志?
我们可以提高日志级别以查看为什么在保存数据库实体时会抛出异常
如何获取每个表的锁数,DB 获取的不同类型的锁(表锁、页锁、行锁数等)
调试此问题的任何其他指针。
仅供参考,我在从这个 cmd 得到的 sqlerror 日志中没有发现任何有用的东西:
SELECT SERVERPROPERTY('ErrorLogFileName')
这是异常的堆栈跟踪:
System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server. See the inner exception and http://go.microsoft.com/fwlink/?LinkId=313468 for more information.
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the …Run Code Online (Sandbox Code Playgroud)