I inherited the below code:
public partial class myWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var username = User.Identity.Name;
SqlConnection MyConnection = new SqlConnection("server=myServer;database=myDatabase;Trusted_Connection=True;");
SqlDataAdapter MyDataAdapter = new SqlDataAdapter("SP_CheckPermissions", MyConnection);
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@loginname", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters["@loginname"].Value = (loginname);
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@loginrole", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters["@loginrole"].Direction = ParameterDirection.Output;
DataSet DS = new DataSet();
MyConnection.Open();
MyDataAdapter.Fill(DS, "LoginRole");
Session.Add("Role", DS);
string loginrole = null;
loginrole = MyDataAdapter.SelectCommand.Parameters[1].Value.ToString();
string role1 = "Librarian";
string role2 = "Principals";
string role3 = "Grade1";
string role4 = "Grade2";
string role5 = "Grade3";
string role6 = "Guidance";
if (loginrole == role1)
{
Server.Transfer("Librarian.aspx", true);
}
else if (loginrole == role2)
{
Server.Transfer("Principals.aspx", true);
}
else if (loginrole == role3)
{
Server.Transfer("Grade1.aspx", true);
}
else if (loginrole == role4)
{
Server.Transfer("Grade2.aspx", true);
}
else if (loginrole == role5)
{
Server.Transfer("Grade3", true);
}
else if (loginrole == role6)
{
Server.Transfer("Guidance.aspx", true);
}
else
{
Server.Transfer("NewUserPage.aspx", true);
}
MyConnection.Close();
}
}
For some reason, I am now getting this timeout error message:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
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.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.]
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +6372097
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6372430
System.Data.SqlClient.SqlConnection.Open() +300
MonogramFoods.WebForm1.Page_Load(Object sender, EventArgs e) +549
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064
This only happened when I added the Guidance.aspx page. The code behind that page looks like this:
public partial class Guidance : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var username = User.Identity.Name;
}
}
}
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1031
Other than including a specific number of connection tries when I connect to my database, what's causing this error by just adding an additional landing page to this code?
What I have tried:
Google search, msdn search, various blogs, debugging the code