Bhavesh Tamrakar
Bhavesh Tamrakar

Reputation: 1

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

I am facing one problem in asp.net Application with sql server database. I am getting Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. In my code stored procedure is taking around 43 seconds and after 30 seconds I am getting this error. For Solving this I have analyzed many sites and found these solutions:

  1. I need to set Connection Timeout=300 in connectionString in web.config file. This point I have done, but still I get the same error.

  2. I also need to set commandTimeout through code. My problem : I am not able to modify the default commandTimeout Because I am using DataTier_Using_SQLClient to connect to database. This does not contain the commandTimeout property .

    Actually default command timeout is 30 seconds only.

Upvotes: 0

Views: 13016

Answers (2)

Bhavesh Tamrakar
Bhavesh Tamrakar

Reputation: 1

Thank you very much Tim B James and January Mmako

Actually I was solving one issue related to one application. DataTier_Using_SQLClient is one class in my application to connect with Database. Then forget this class.

I have solved this issue by creating connection using SqlConnection. See the code below. Using this code you can solved the Time Expired Error and can call retrieve stored procedure having one parameter that need to pass:

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

use the below code where you want

string connetionString = null;

SqlConnection connection ;

SqlDataAdapter adapter ;

SqlCommand command = new SqlCommand();

SqlParameter param ;

DataSet ds = new DataSet();

//You can specify this connectionString in web.config or here

connetionString = "Data Source=servername;
Initial Catalog=PUBS;User ID=sa;
Password=yourpassword;
Connection Timeout=300";


connection = new SqlConnection(connetionString);


connection.Open();

command.Connection = connection;

command.CommandType = CommandType.StoredProcedure;

command.CommandText = "sp_Retrieve_ProcedureName";


param = new SqlParameter("@paramName", ParamValue);

param.Direction = ParameterDirection.Input;

param.DbType = DbType.Int32;

command.Parameters.Add(param);

adapter = new SqlDataAdapter(command);


adapter.SelectCommand.CommandTimeout = 120;


adapter.Fill(ds);

you can use this ds (DataSet) object where ever you want.

Upvotes: 0

January Mmako
January Mmako

Reputation: 330

Assuming you are using an Adapter

DataSet dsData = new DataSet();
SqlConnection conn = new SqlConnection(GetConnection());
SqlDataAdapter adapter = new SqlDataAdapter(strQuery, conn);
adapter.SelectCommand.CommandTimeout = 120;

Upvotes: 1

Related Questions