views:

195

answers:

3

i don't want to encapsulate every call in a try catch block

is there an event i can subscribe to, for when a connection is lost or timesout so that i can reconnect..

or some way to not check every linq query.

and if not why not!

Edit: Does Linq to Entity's have this?

Edit: I'm using Microsoft SQL Azure, and it drops connections alot.

Edit: I open a new connection on every call to the db. so its not that I'm leaving the connection open.

+1  A: 

Even if there were such event (not sure) you still could not rely on it. A network connection can suddenly get broken, database engine be busy doing some other query a timeout is always a possibility. Better watch directly a query if it's succeeded or failed, regardless of the reason.

Developer Art
A: 

Why are you getting so many drops? Are you hanging on to a data context object for a long time? It's cheap to construct one, so just construct a new one when you start a new unit of work.

From this msdn blog

It is better to err on the side of shorter lifetime - a unit of work or even a single request for stateless servers are good patterns to start with.

Steve Cooper
i'm using windows azure sql server.. it drops all the time..
Matt Peters
+1  A: 

You could consider writing your own LINQ provider (using much of the existing one's functionality) that adds exactly this feature. It might turn out to be less work than handling the exception each and every time.

Danut Enachioiu