Hello,
I think my question is more or less about how to properly dispose of objects Ive used. Im coming over from ASP 3.0 where Ive learned to dispose of everything I dont need, so I do the same thing in VB.NET, though lately as my project grows I think Im fighting with the Garbage Collection.
I can click on a page where I access the DB and get an error like the one below (the exact error varies but most of the time its either one of those mentioned) then I can referesh the page and everything works just fine. So it leads me to believe that the GC is kicking in at times where Im dispousing of some objects (Readers, OleDbCommand, OleDbConnection etc.).
Whats the proper way of dispousing of ojects and is that whats causing my problems ? In most VB.NET examples people dont dispouse of objects so I guess I should do the same ? Thanks for your time.
Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
Source Error:
Line 65: MyCMD = New OleDb.OleDbCommand(SQL, MyConn)
Line 66: MyRead = MyCMD.ExecuteReader
> Line 67: MyCMD.Dispose()
Line 68: While Not MyRead.Read = False
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 56: MyCMD = Nothing
Line 57: dRepeater.DataSource = DS
> Line 58: MyConn.Dispose()
Line 59: MyConn = Nothing
Line 60: dRepeater.DataBind()
I think my question is more or less about how to properly dispose of objects Ive used. Im coming over from ASP 3.0 where Ive learned to dispose of everything I dont need, so I do the same thing in VB.NET, though lately as my project grows I think Im fighting with the Garbage Collection.
I can click on a page where I access the DB and get an error like the one below (the exact error varies but most of the time its either one of those mentioned) then I can referesh the page and everything works just fine. So it leads me to believe that the GC is kicking in at times where Im dispousing of some objects (Readers, OleDbCommand, OleDbConnection etc.).
Whats the proper way of dispousing of ojects and is that whats causing my problems ? In most VB.NET examples people dont dispouse of objects so I guess I should do the same ? Thanks for your time.
Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
Source Error:
Line 65: MyCMD = New OleDb.OleDbCommand(SQL, MyConn)
Line 66: MyRead = MyCMD.ExecuteReader
> Line 67: MyCMD.Dispose()
Line 68: While Not MyRead.Read = False
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 56: MyCMD = Nothing
Line 57: dRepeater.DataSource = DS
> Line 58: MyConn.Dispose()
Line 59: MyConn = Nothing
Line 60: dRepeater.DataBind()