Question

I have a mobile application that connects directly to an instance of SQL Server 2008.

Normally, if this was was a desktop application I would wrap every database call in a using statement:

using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{ }

And if it was a mobile application connecting to a local compact database, I would leave the connection open for the life of the application (since it has to be rebuilt every time).

But, now I'm faced with a mobile application that's connecting to a real server...so would it be best to follow the desktop route, or the mobile route? At first I was going to do the desktop route but then I remembered that pooling isn't even supported on the mobile version so maybe it would be best to leave it open?

Was it helpful?

Solution

Mobile devices are wireless - battery operated.

They are designed to use very little power by shutting down resources when not in use. That goes for your wireless radio!

It will turn back on when you need it, but an Open connection will not know that.

My guess is you are going to run into connection issues with that. The software will make one call and wait for a response.

If the wireless radio was not connected at the time, it may or may not throw an error for you to see.

Whether it throws an error or not, how do you go about re-establishing a connection with your application? Unless you write code in there, you would need to restart your app.

I do not think there is any RIGHT or WRONG way to do this, but I would think opening the connection only when you needed it would be a BEST PRACTICE idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top