user1512559
user1512559

Reputation:

Connection pool in LINQ to SQL

In a C# 2008 windows application that use call a web service, there is a large volume of statements that look like the following: In a C# 2008 application, I am using linq to sql statements that look like the following:

//Code

  TDataContext TData = new TDataContext();
  var TNumber = (from dw in cms_TData.people
  where dw.Organization_Name.ToUpper().Trim() == strOrgnizationName.Trim().

Right before every call that is made to the database, a new data context object is created.

Would this cause some kind of connection pooling problem to the database? If so, can you tell me how to resolve the connection pooling problem?

Upvotes: 2

Views: 1941

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

Connection pooling is not a problem, it is a solution to a problem. It is connection pooling that enables you write

TDataContext TData = new TDataContext();

without a fear of exhausting the limited number of RDBMS connections, or slowing down your system to a crawl due to closing and re-opening connections too often. The only issue that you may run into with the code like that is caching: whatever is cached in TData is gone when it goes out of scope, so you may re-read the same info multiple times unnecessarily. However, the cache on RDBMS side would help you in most cases, so even the caching is not going to be an issue most of the time.

Upvotes: 2

A Coder
A Coder

Reputation: 3046

A DataContext is a lightweight object which closes the database connection as soon as it has completed as a task.

Consequently, creating a large number of these objects shouldn't cause a connection pooling problem unless, possibly, they are being created simultaneously on different threads.

Upvotes: 0

Related Questions