Timeout setting for SQL Server

后端 未结 3 1800
半阙折子戏
半阙折子戏 2020-12-08 10:48

I am using VSTS 2008 + ADO.Net + C# + .Net 3.5 + SQL Server 2008. I am using ADO.Net at client side to connect to database server to execute a store procedure, then return r

3条回答
  •  一整个雨季
    2020-12-08 10:53

    As gbn already mentioned, there are two types of timeouts:

    1) Connection Timeout: this is controlled by your connection string:

    Data Source=.;Initial Catalog=TestDB;
       Trusted_Connection=true;Asynchronous Processing=true
    

    If you add a Connect Timeout=120 to this string, your connection will try for 120 seconds to get opened and then aborts.

    Data Source=.;Initial Catalog=TestDB;
       Trusted_Connection=true;Asynchronous Processing=true;
       Connect Timeout=120;
    

    2) Command timeout: for each command, you can also specify a timeout - ADO.NET will wait for that amount of time before cancelling out your query. You specify that on the SqlCommand object:

        using (SqlCommand RetrieveOrderCommand = new SqlCommand())
        {
           RetrieveOrderCommand.CommandTimeout = 150;
        }
    

提交回复
热议问题