Anyone know of a webpage that defines the various parameters and configuration options for database connection strings?
My app is having trouble recognizing whether the database is available. The app will work until the database goes offline. When the database comes back online, the app continues to think that the database is unavailable. My hope is that I can tweak some
connection string setting to solve the problem, but any advice or ideas are appreciated.
Below is the code used in global.asax.cs. The method is called in Application Start.
may you please advise the error message you see on your end? With an error message, it will be easier for me and the rest of the forum members to help.
Application_Start() method will fire only once during a application lifecycle. We place code which we want to execute only once, inside that method. So no wonder your application behave like your database is offline even though it comes online. You have
to redesign your architecture so it will always look IsDatabaseAvailable() method (In otherwords, place it somewhere where it will get executed before you perform database operation). For example, you can place that method inside Page_Load() method of every
page.
I moved IsDatabaseAvailable to Application_BeginRequest within global.asax.cs. In addition, I added a finally block to the try catch with a line for "connection.Close();". The problem was that the connection pool was being exhausted. I was working from
the assumption that the connection would be closed automatically when the request was complete, but it turns out that you have to close the connection manually.
I was working from the assumption that the connection would be closed automatically when the request was complete, but it turns out that you have to close the connection manually.
Hello,
It's always a good practise to release the resources once you finish the job. In that way, you can develop quality products with higher performance.
bluesherpa
Member
130 Points
48 Posts
connectionString parameters
Feb 04, 2012 05:07 PM|LINK
Anyone know of a webpage that defines the various parameters and configuration options for database connection strings?
My app is having trouble recognizing whether the database is available. The app will work until the database goes offline. When the database comes back online, the app continues to think that the database is unavailable. My hope is that I can tweak some connection string setting to solve the problem, but any advice or ideas are appreciated.
Below is the code used in global.asax.cs. The method is called in Application Start.
Thanks,
Ed
protected void Application_Start( object sender, EventArgs e ) { Utility.ErrorLog("Starting application..."); if (!IsDatabaseAvailable()) { Utility.Log("critical", "Database connection unavailable"); return; } RegisterRoutes(RouteTable.Routes); }protected void Application_Start( object sender, EventArgs e ) { Utility.ErrorLog("Starting application..."); if (!IsDatabaseAvailable()) { Utility.Log("critical", "Database connection unavailable"); return; } RegisterRoutes(RouteTable.Routes); } public static Boolean IsDatabaseAvailable() { SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebConnectionString"].ConnectionString);// + ";Connect Timeout=5"); try { connection.Open(); } catch { ApplicationError = true; return false; } return true; } protected void Application_BeginRequest( object sender, EventArgs e ) { HttpApplication app = sender as HttpApplication; if (ApplicationError && app != null && app.Request.AppRelativeCurrentExecutionFilePath != "~/maintenance/db-unavailable.aspx") { Response.Redirect("~/maintenance/db-unavailable.aspx"); } }necro_mancer
Star
8169 Points
1595 Posts
Re: connectionString parameters
Feb 05, 2012 01:58 AM|LINK
hi bluesherpa,
may you please advise the error message you see on your end? With an error message, it will be easier for me and the rest of the forum members to help.
thanks
Professional SQL 2008 R2 Service
bluesherpa
Member
130 Points
48 Posts
Re: connectionString parameters
Feb 06, 2012 03:56 PM|LINK
Thanks, necro_mancer. I will modify the code to see if I can record the specific error message.
Ruchira
All-Star
44382 Points
7194 Posts
MVP
Re: connectionString parameters
Feb 07, 2012 11:27 AM|LINK
Hi,
Application_Start() method will fire only once during a application lifecycle. We place code which we want to execute only once, inside that method. So no wonder your application behave like your database is offline even though it comes online. You have to redesign your architecture so it will always look IsDatabaseAvailable() method (In otherwords, place it somewhere where it will get executed before you perform database operation). For example, you can place that method inside Page_Load() method of every page.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.bluesherpa
Member
130 Points
48 Posts
Re: connectionString parameters
Feb 07, 2012 08:31 PM|LINK
Thanks Ruchira.
I moved IsDatabaseAvailable to Application_BeginRequest within global.asax.cs. In addition, I added a finally block to the try catch with a line for "connection.Close();". The problem was that the connection pool was being exhausted. I was working from the assumption that the connection would be closed automatically when the request was complete, but it turns out that you have to close the connection manually.
Ruchira
All-Star
44382 Points
7194 Posts
MVP
Re: connectionString parameters
Feb 08, 2012 04:47 AM|LINK
Hello,
It's always a good practise to release the resources once you finish the job. In that way, you can develop quality products with higher performance.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.