首页 > 其他 > 详细

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

时间:2015-03-30 18:50:51      阅读:182      评论:0      收藏:0      [点我收藏+]

问题:

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

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的风险。





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

原文:http://blog.csdn.net/bubu05690523/article/details/44752743

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!