Reputation: 151
I've got a website in asp.net / c# that updates an SQL server, which currently is working fair enough. However, I'm looking at taking it onto mobile devices and wondering what to do if the device loses connection. Basically, I'm wanting to catch it if it can't connect when the user tries to make edits.
The basic code is:
try
{
Conn.Open();
}
catch (SqlException)
{
Session["HaveWeUpdated"] = 0;
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alertMessage", "alert('Error')", true);
}
finally
{
Conn.Close();
}
Which should bring up the pop-up message if it can't connect, as well as set our HaveWeUpdated session value to 0. Unfortunately, at the moment, when I try it (simply by pulling the cable out of my PC) it goes to the standard IE8 "diagnose connection problems" page and does NOT show the pop-up message - hence, I guess, it's not being caught.
Upvotes: 0
Views: 1070
Reputation: 14919
I think you are a bit confused about how your web site is working.
The code you have written here, works on the server, not on the mobile device. Thus, it checks whether it can connect to database; it does not check whether you can connect from your mobile device to the website.
Simply, when you put the cable out, the connection between your local machine and the web server is lost.
To clarify more:
1- Web browser requests a page
2- Web server receives the request
3- Web server calls the database server
4- Web server receives the response from DB server
5- Web server processes the response
6- Web server sends the response to the browser
7- Browser processes and displays the response.
Upvotes: 4