2

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?

2
  • what connection pooling problem are you mentioning? Commented Apr 12, 2013 at 10:14
  • Which we generally use to conenct to the DB. Commented Apr 12, 2013 at 10:15

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments