Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time out Exception in C#.net

Tags:

c#

c#-4.0

 public DataTable GetDailycardReport(DailyReportPL dailyreportpl)
    {
        DataTable dtGetDailycardReport = new DataTable();
        try
        {
            SqlParameter[] arParams = new SqlParameter[2];

            arParams[0] = new SqlParameter("@farmername", typeof(string));
            arParams[0].Value = dailyreportpl.farmername;

            arParams[1] = new SqlParameter("@batchno", typeof(int));
            arParams[1].Value = dailyreportpl.batchno;

            dtGetDailycardReport.Load(SqlHelper.ExecuteReader(connection.ConnectionString, CommandType.StoredProcedure, "k_DailyCardreport", arParams));
        }
        catch (Exception ex)
        {

            //DBExceptionPublisher exc = new DBExceptionPublisher();
            //exc.Publish(ex);
        }
        finally
        {

        }
        return dtGetDailycardReport;

    }

Exception ::

"Timeout expired.  The timeout period elapsed prior to completion of 
    the operation or  the   server is not responding."

When I pass parameters to stored procedure its caught an exception and displaying above message".How to increase command timeout to 200 in webconfig file. I searched in google but no optimized result.

like image 398
Bhagavan Avatar asked Dec 09 '22 14:12

Bhagavan


2 Answers

You can set it on your command object also

   cmd.CommandTimeout = 60;

Specify your time in seconds.

like image 51
prospector Avatar answered Dec 11 '22 08:12

prospector


It can be set in the connectionstring, like the following where it is set to 200 seconds.

"Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI;Connection Timeout=200"

Source

like image 21
Peter Rasmussen Avatar answered Dec 11 '22 07:12

Peter Rasmussen