DSharper
DSharper

Reputation: 3217

best practice for avoid connection timeout when using LINQ to SQL

i need to know best practice for avoid connection timeout when using LINQ to SQL in .net applications specially when returning IQueryable<T>from data access tiers or layers.

I get "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached." error when testing my asp.net application for webstress tests ?

Upvotes: 6

Views: 13182

Answers (3)

Sbspider
Sbspider

Reputation: 399

Actually, you might wanna check if the server is actually up. I ran into this problem - turns out i forgot to restart the MSSQL service after stopping it for maintenance.

Basic noob mistake, but caused me a weeks headache

Upvotes: 1

Mohammed A. Fadil
Mohammed A. Fadil

Reputation: 9377

You need to increase the CommandTimeout property value in your DataContext object (the default value is 30 seconds), it is measured in seconds, for example:

var myDataContext = new MyDbDataContext(myConnectionString) { CommandTimeout = 120 }; var rows = myDataContext.sp_Agent__Select(agentId);

Upvotes: 4

PrateekSaluja
PrateekSaluja

Reputation: 14936

http://www.geekscrapbook.com/2010/08/13/connection-timeout-using-linq-datacontext/

Link will explain you what will be the reason of Timeouut using LINQ to SQl.You can manually increase the query execution time.By default its 30 sec. According to Visual studio 2008 Go to

Tools->Database Tools->Query & view design

Here you will get the option to increase the execution time. Hope it helps you.

Good Luck

Upvotes: 7

Related Questions