2

My website works fine most of the time, but sometimes I get timeout expired errors and can't do anything for 1-15 minutes. When error occurs for first time it is:

The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) (...)

And after that, if I try to refresh page I keep getting:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server  is not responding.   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
(...).

Every connection that I use is either SqlDataSource, or opened in code like this:

SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Faktury_RebuildConnectionString"].ToString());
SqlCommand myCommand = new SqlCommand("Command String", myConnection);
try{                    
  myConnection.Open();
  somecodehere()
}
finally
{
  if (myConnection != null)
  {
    myConnection.Close();
  }
}

Where my connection string in web.config is Data Source=xxx\;Initial Catalog=xxx;User ID=xxx;Password=xxx;Max Pool Size=100;.

I tried to turn off pooling and it didn't help. I checked if every connection is handled properly and it is. All SELECTs are good - means they don't take much time. Especially I can see that when application is working properly.

This error also occurs when I leave my site for some time (15 - 60 min) and enter it again for first time; then all I need to do is refresh it and it works fine then.

In times of this error SQL Server works fine and other website using mostly same select queries works fine.

Does anybody have suggestion what may be wrong there? I've run out of ideas.

Edit: It would be useful to at least not having to refresh page after being idle for longer time and getting this one time timeout expired.

Zaphood
  • 2,509
  • 2
  • 22
  • 21

1 Answers1

0

There are two main Timeout property in ADO.NET.

  1. Connection Timeout for Connection. It could be solved by setting ConnectionTimeout property of Connection object in Connection String.
  2. Timeout for Data access ( Command Object ). You can set CommandTimeout property to Command object. I recommend you set CommandTimeOut property to bigger one value. Try this. Please let me know whether this can handle this problem or not. If you have any further questions, please feel free to let me know.
Tan
  • 778
  • 3
  • 18
  • 36
  • Thank you for answer; I tried it and unfortunetly it doesnt solve my problem. As i said, application can't connect to server for 10-15 minuts, but all queries are executed in less than 1 sec. And while my application cant do anything, server works fine and i can connect to it with other application. Any other ideas? – Zaphood Sep 12 '11 at 09:32
  • please check this link hope this will help http://stackoverflow.com/questions/1062035/how-to-config-socket-connect-timeout-in-c – Tan Sep 12 '11 at 14:49