Last post Feb 26, 2011 05:12 PM by duttavr
Feb 09, 2011 03:54 PM|feelexit126|LINK
Here's my code, I am using "Data Access Application Block" in ObjectDataSource's class file.
public class Hospital
private Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("Conn");
public SqlDataReader sDR;
public SqlDataReader GetHospitals()
RefCountingDataReader dr = (RefCountingDataReader)_db.ExecuteReader("GetHospitals");
in my code, I didnt dispose the dataReader. will it mess up my connection management ? I want to make sure that DbConnection is properly closed.I found this from "hands on lab"."You are not doing any connection management here, but it is very important to Dispose the data reader returned. This is accomplished by the using statement in the code above. When the data reader is disposed, the underlying DbConnection is also closed."please let me know if what I did is ok, if not how do i close DbConnection properly.if you are wondering why I dont use "using" statement. basically, I bind my gridviews using ObjectDataSource, if I am using "using" statement in my code, then DataReader will be disposed, its giving me error message.
I posted that problem here: http://entlib.codeplex.com/Thread/View.aspx?ThreadId=245208
Feb 09, 2011 05:29 PM|amitchandnz|LINK
You will have to close the reader yourself:
You can close this as RefCountingDataReader.Close;
Feb 15, 2011 03:17 PM|sachingusain|LINK
You must close the reader immediately after using it. Or, you can close/dispose it off in the "finally" section of the try-catch-finally block.
Feb 26, 2011 05:12 PM|duttavr|LINK
using will not do any magic regarding connections. It just calls Dispose method at the end of using scope.
Please read this thread,
it helps you to understand "Using" and "Dispose".
So in this case, you would need to call Dispose methdo yourself.
public void YourMainFunction()
SqlDataReader reader = GetHospitals();