目前,我的 Windows 服务每天处理大约 1500 笔交易。大约每周一次,我在使用 LINQ 完成的插入时遇到随机超时异常。
例外是:
Exception (SqlException) System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Linq 查询是:
dc.TransactionLoggings.InsertOnSubmit(new TransactionLogging()
{
DateAdded = DateTime.UtcNow,
InputMessage = message,
DocId = documentID.ToString(),
TransactionStatus = transactionStatus
});
dc.SubmitChanges();
关于如何诊断此问题的任何想法/建议?
非常感谢你的帮助,菲奥娜
更新
表结构为:
CREATE TABLE [dbo].[TransactionLogging](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[InputMessage] [nvarchar](max) NULL,
[CCHMessage] [nvarchar](max) NULL,
[DocId] [char](20) NOT NULL,
[TransactionStatus] [char](5) NOT NULL,
[DateAdded] [datetime] NULL,
[LastUpdate] [datetime] NULL,
[SentDate] [datetime] NULL,
约束 [PK_TransactionLogging] 主键集群([ID] ASC)WITH(PAD_INDEX = OFF,STATISTICS_NORECOMPUTE = OFF,IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS = ON,ALLOW_PAGE_LOCKS = ON)ON [PRIMARY])ON [PRIMARY
此外,最近的 2 次交易超时发生在当天的第一笔交易中。我敢肯定,这绝非巧合!
也只是想知道是否有人对我的代码的以下更新有任何想法:
任何意见?!!!
using (MiddlewareDBDataContext dc = new MiddlewareDBDataContext(ConfigurationWrapper.ActivityLoggingDatabase_ConnectionString))
{
dc.TransactionLoggings.InsertOnSubmit(new TransactionLogging()
{
DateAdded = DateTime.UtcNow,
InputMessage = message,
DocId = documentID.ToString(),
TransactionStatus = transactionStatus
});
try
{
dc.SubmitChanges();
}
catch (SqlException ex)
{
//Wait for 30 seconds then retry..
System.Threading.Thread.Sleep(30000);
dc.SubmitChanges();
}
}