0

I'm facing a strange problem with my website that it doesn't seem to be using the connection pooling. I am using linq to sql to call stored procs and return the list of items but not sure if its closing the connections/disposing the data context class or not.

my code looks like this

public list<data.dto.category> getall()
{
var db = new mydatacontext();

return db.getCategories().ToList();
}

how do I make sure that I am closing the connections??

Thanks

  • 1
    Have a look at the accepted answers: http://stackoverflow.com/questions/389822/when-should-i-dispose-of-a-data-context or this related: http://stackoverflow.com/q/400866/284240 In short: they are closed automatically after the query. – Tim Schmelter Sep 25 '12 at 21:01

1 Answers1

0

Try creating your context with "using" statement.

    using (MyDataContext context = new MyDataContext())
    {
         // do stuff
    }
DmitriG
  • 98
  • 7