Datacontext is designed to open when you use it and then throw it away. For example:
using (var dc = new MyDataContext())
dc.sp_DailyJob();
Immediately after the block, the usingdatacontext returns back to the connection pool.
Now, if you cache the DataContext in a local module, it may not work for a while. Then SQL Server will eventually close your connection because it has been idle for too long. The next call generates a message Timeout expired.
I would remove the caching DataContext and continue to create a new DataContext for each query or query you run. Dispose of them as soon as you can. There is no overhead because connections are cached using an optimized connection pool.
source
share