2
votes

I have created a login page in asp.net and created a user and role in asp.net membership, after login I have a query in my page load method to check the role of user and display a view of the page as per that user but I am getting this error.

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

My code:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.User.Identity.IsAuthenticated)
    {

        if (Roles.IsUserInRole("Manager"))
        {

            NavigationMenu.Visible = false;
            NavigateMenu1.Visible = true;

                creategrid();
        }
    }
}

This exception only occurs as I run my application for the first time and as I refresh page try to login again then there is no exceptions. please help me as I am new this.

3
Can you try to debug through your code and find out which command is throwing the exception? It seems like some query is running longer than it should be. I suggest starting with Application_Start() method in your Global.asax file.user848765

3 Answers

2
votes

The error message is trying to say that, its taking longer time to establish a connection than the default timeout period..

Though you can increase the timeout, I would suggest you not do it..

find out why its happening.. If its happening frequently, then may be your connection pool may not be having sufficient connections at that time..if so, you can increase the min pool size or max pool size and have reasonable Connection Lifetime, etc.,

see http://msdn.microsoft.com/en-us/library/8xx3tyca(v=vs.71).aspx

1
votes

In the command object set commandTmeout property.

cmd.CommandTimeout = 9000;

1
votes

Add timeout of your SqlCommand. Please add time is in second.

// Setting command timeout to 1 second
 cmd.CommandTimeout = 1;