欢迎投稿

今日深度:

Timeout expired. The timeout period elapsed prior to complet

Timeout expired. The timeout period elapsed prior to completion of the operation or the server...,elapsedserver..


问题:

最近程序总会抛出如下异常:

An exception of type'System.Data.SqlClient.SqlException' occurred and was caught.

----------------------------------------------------------------------------------

Type :System.Data.SqlClient.SqlException, System.Data, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089

 Message : Timeoutexpired.  The timeout period elapsedprior to completion of the operation or the server is not responding.

Source : .Net SqlClient Data Provider......

......Database.ExecuteReader(DbCommandcommand)......

读取数据超时。

然后就去看了下DataBase里对应的tables,发现table的结构简单,但是数据量很大,有几十万上百万条。再看一下有没有建Indexes/Keys,发现没有,恍然大悟。


解决方法:

根据表的结构,建立了Indexes/Keys下的 Unique key,类似如下:

ALTER TABLE [dbo].[ZData]
 add  CONSTRAINT [IX_ZData] UNIQUE NONCLUSTERED 
(
	[Pid] ASC,
	[EntryID] ASC,
	[Date] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, 
ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
测试,发现速度快很多,减小了timeout的风险。





www.htsjk.Com true http://www.htsjk.com/shujukunews/7242.html NewsArticle Timeout expired. The timeout period elapsed prior to completion of the operation or the server...,elapsedserver.. 问题: 最近程序总会抛出如下异常: An exception of type'System.Data.SqlClient.SqlException' occurred and was...
评论暂时关闭