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

來源:互聯網
上載者:User

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的風險。





相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.