System.Data.SqlClient.SqlException: 逾時時間已到—解決之道

來源:互聯網
上載者:User

     前幾天在給公司做一個統計日報頁面,因為要查詢的資料量非常巨大,改為預存程序來執行查詢依然速度緩慢,更為鬱悶的是當我測試此頁面的時候,總是出錯——System.Data.SqlClient.SqlException: 逾時時間已到。

     解決之道分為兩步:

     1.在web.config中的<system.web>標籤中插入下面這句:

        <httpRuntime maxRequestLength="2097151" executionTimeout="720000"/>

        maxRequestLength的最大值好像就是2097151了,再大了會報錯。executionTimeout的值完全是我亂寫的,但至少還沒報錯。

     2.在串連資料庫的代碼中加入如下一句:

       string ConStr = "Data Source=……;Initial Catalog=……;Persist Security Info=True;User ID=……;Password=……";
        SqlConnection conn = new SqlConnection(ConStr);
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = this.sql;
        cmd.CommandTimeout = 10000;   //要加這一句
        conn.Open();
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adapter.Fill(ds);
        conn.Close();

     

       如果這樣修改之後還有問題,那你真得考慮是不是要更換你的伺服器了~……呵呵!

 

       註:此文章屬原創作品,轉載請註明出處:http://www.cnblogs.com/luzx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.