Reputation: 21
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.
Upvotes: 2
Views: 7248
Reputation: 6590
Add timeout of your SqlCommand
. Please add time is in second
.
// Setting command timeout to 1 second
cmd.CommandTimeout = 1;
Upvotes: 1
Reputation: 590
In the command object set commandTmeout property.
cmd.CommandTimeout = 9000;
Upvotes: 1
Reputation: 3850
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
Upvotes: 2