Avoid application hanging

  • Thread starter Thread starter Tim De Vogel
  • Start date Start date
T

Tim De Vogel

Hi,

I developed a pocketpc application that connects directly to a SQL Server
(so not the mobile CE edition) usign wifi. My problem is that when the
server / wifi is unavailable (due to bad connection, server restart or
whatever) the mobile application hangs, even with a try.. catch around the
connection parts. Is there a clean way to "detect" for the sql server
availability or to at least make sure my application doesn't hang and gives
a proper msgbox failure instead of having to go to memory manager to quit
the application?
 
Try using the ConnectionManager conponent from OpenNETCF to establish a
connection first. Then once connected, do the remote SQL connection.
 
Yes, you have to handle the case where the network connection might not be
available. Threading is the common solution to processes, like creating a
network connection, etc. which might take a long time. If you did the
database connect in a thread separate from the thread driving the user
interface, the application wouldn't be locked (you could show progress in a
status bar, or in any number of different ways, or even allow the user to
cancel the database connect).

Paul T.
 
Tim,

What I do in this situation which has worked perfectly for me is that I
Ping the the server before opening the connection and if the ping comes
back ok then I try and open the connection. Of course I have the server
machine responding to pings.

--Miguel
 
You could also use the System.Net.Dns class to determine the current IP
address for the device. anything other than 127.0.0.1, and you should have a
valid network connection.

sample code would look something like:

IPHostEntry hostInfo = Dns.GetHostByName(Dns.GetHostName());

if ((hostInfo != null) && (hostInfo.AddressList != null) &&
(hostInfo.AddressList.Length > 0)) {
if (0 != string.Compare("127.0.0.1",
hostInfo.AddressList[0].ToString(), false, CultureInfo.CurrentUICulture) {
// valid network connection
}
else {
// invalid network connection
}
}
else {
// invalid network connection
}
 
This looks like an easy and good suggestion. I'll try this!
Thank you all for taking the time to reply.

--
Tim De Vogel
S-Data NV
http://www.s-data.be



allen said:
You could also use the System.Net.Dns class to determine the current IP
address for the device. anything other than 127.0.0.1, and you should
have a
valid network connection.

sample code would look something like:

IPHostEntry hostInfo = Dns.GetHostByName(Dns.GetHostName());

if ((hostInfo != null) && (hostInfo.AddressList != null) &&
(hostInfo.AddressList.Length > 0)) {
if (0 != string.Compare("127.0.0.1",
hostInfo.AddressList[0].ToString(), false, CultureInfo.CurrentUICulture) {
// valid network connection
}
else {
// invalid network connection
}
}
else {
// invalid network connection
}



Tim De Vogel said:
Hi,

I developed a pocketpc application that connects directly to a SQL Server
(so not the mobile CE edition) usign wifi. My problem is that when the
server / wifi is unavailable (due to bad connection, server restart or
whatever) the mobile application hangs, even with a try.. catch around
the
connection parts. Is there a clean way to "detect" for the sql server
availability or to at least make sure my application doesn't hang and
gives
a proper msgbox failure instead of having to go to memory manager to quit
the application?
 
Back
Top