By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,138 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,138 IT Pros & Developers. It's quick & easy.

"Timeout expired" when calling SqlConnection.Open()

P: n/a
Hi,

I've made a HttpModule which deals with user authentication. On the first
request in a users session, it fetches data from a SQL Server using the
following code:
using (SqlConnection connection = new
SqlConnection(ConfigurationSettings.AppSettings["Database.Connection"]))
{
connection.Open();
SqlCommand sqlCommand = new SqlCommand("GetAdvisorEnterpriseLogin",
connection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@InputUsername",
HttpContext.Current.User.Identity.Name);
SqlDataReader reader = sqlCommand.ExecuteReader();
reader.Read();
username = (string) reader["Username"];
password = (string) reader["Password"];
reader.Close();
}

However, the first 1-3 times I access the page after a recompile (and once
in a while otherwise), I get the following exception:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired. The
timeout period elapsed prior to completion of the operation or the server is
not responding.

I also get the exception after not using the system for a while, but I
haven't experienced when the system is "in use", i.e. when the previous
request was no more than a couple of minutes ago.

Does anyone know what could cause this error, and how I can prevent it from
happening?

Regards,
Nils Magnus Englund
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You might need to specify command timeout.
Try setting sqlCommand.CommandTimeOut (seconds). The default is 30 sec
which may not be enough for your application.

Thanks
Ravindra

Nov 19 '05 #2

P: n/a
No, that's not it - the query is very fast...
Regards,
Nils Magnus

"Ravindra Sadaphule" <rs********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
You might need to specify command timeout.
Try setting sqlCommand.CommandTimeOut (seconds). The default is 30 sec
which may not be enough for your application.

Thanks
Ravindra

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.