A
Andrus
Jon, I checked MSDN doc:
MSDN doc:
A DataContext opens and closes a database connection as needed if you
provide a closed connection or a connection string.
So LINQ to SQL closes passed connection object *without* dispose to be able
to re-open it later.
MSDN doc: In general, you should never have to call Dispose on a
DataContext.
So MSDN doc considers *bad* practice to dispose DataContext object.
I tried to use your recommendations and Marc sample to dispose immediately
and created code
IQueryable<T> Queryable;
using ( var db = nortwind(CONNSTRING) ) {
Queryable = from b in db.Customers() select b;
}
in paged grid data retrieval method (executed if user presses page down in
virtual grid) I used
IList<T> SupplyPageOfData(int lowerPageBoundary, int rowsPerPage) {
return Queryable.Skip(lowerPageBoundary).Take(rowsPerPage).ToList();
}
line
Queryable.Skip(lowerPageBoundary).Take(rowsPerPage).ToList();
causes exception:
Connection is not open
How to fix ?
Andrus.
I don't believe a LINQ to
SQL context will close its connection automatically without calling
Dispose on it - at least not in a timely manner.
MSDN doc:
A DataContext opens and closes a database connection as needed if you
provide a closed connection or a connection string.
So LINQ to SQL closes passed connection object *without* dispose to be able
to re-open it later.
it's good practice to dispose of an object which implements
IDisposable when you know you've finished with it.
MSDN doc: In general, you should never have to call Dispose on a
DataContext.
So MSDN doc considers *bad* practice to dispose DataContext object.
I tried to use your recommendations and Marc sample to dispose immediately
and created code
IQueryable<T> Queryable;
using ( var db = nortwind(CONNSTRING) ) {
Queryable = from b in db.Customers() select b;
}
in paged grid data retrieval method (executed if user presses page down in
virtual grid) I used
IList<T> SupplyPageOfData(int lowerPageBoundary, int rowsPerPage) {
return Queryable.Skip(lowerPageBoundary).Take(rowsPerPage).ToList();
}
line
Queryable.Skip(lowerPageBoundary).Take(rowsPerPage).ToList();
causes exception:
Connection is not open
How to fix ?
Andrus.