Andrus,
Generally speaking, a context is not meant to be open for the life of an
application. It implies that you want to keep track of all the objects that
were ever created, or ever will be created in the scope of your app, and
generally, that is way too broad.
Rather, when you have a specific group of operations that you are going
to perform, you should create a new instance of the context, use it, and
then dispose of it. Your app is not one giant context, rather, you have
multiple sub-functions which really are their own contexts. You need to
identify these and then work from there.
Also, I seriously doubt that the context is keeping the database
connections open. That's just horrible practice. While I am not positive,
I am guessing that there is some connection pooling going on and that those
connections are what are actually being dropped. The actual connections in
code are closed correctly. Keeping them open would provide no benefits to
the context.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Andrus" <ko********@hot.eewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
For winforms application with multiple related forms it is reasonable to
create Linq database context object in start of application.
Context object is released only when application exits.
So connection to database may remain open for all application run time.
For such a long time, some routers close connection. This causes
Connection
is broken error in application.
How to fix this ?
Andrus.