我是C#和SQL Server的新手;我寫在T-SQL一個簡單的存儲過程,並在C#與下代碼調用:如何解決C#中的連接超時錯誤?
da = new SqlDataAdapter("select_equals_Cycle", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
ds = new DataSet();
da.Fill(ds, "select_equals_Cycle");
,但在這條線:
da.Fill(ds, "select_equals_Cycle");
我得到這個錯誤:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
我的連接字符串是:
string conn = "Data Source=.;Initial Catalog=ClubEatc;Integrated Security=True;Connect Timeout=30;";
我該如何解決這個問題?謝謝。
你需要找到超時的根本原因。是否因爲你試圖從數據庫中加載超過千兆字節?你在等鎖嗎?你有一個非常緩慢的網絡?你有*網絡嗎?你總是可以增加超時時間,但除非你掌握了它爲什麼不能成爲修復的原因,更像是一個繃帶。 –
那麼如果所有其他的都失敗了,你可以增加連接字符串的超時時間 - 如果這個過程運行的時間很長 - 但是如果一個存儲過程運行超過30秒來填充一個數據集,那麼這個過程效率會很低,設置您需要的負載。 – Adwaenyth
嘗試此鏈接中的步驟http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation –