IDisposable problem

AJL

Newcomer
Joined
Jul 8, 2003
Messages
1
I was wondering if someone could comment on a Dispose problem I have encountered. I have a biz object that opens a DAL object and calls the DAL object several times. The DAL object runs the following (edited for readability) data factory function, the selectAuditor is a class level variable that implements the Dispose function because it has a connection object. I follow the exact guidelines for using IDisposable. The SelectAuditor has two main functions SelectSetup and SelectAudit, both of these functions first check to see if the disposed variable is true and throws the ObjectDisposedException if necessary. The first call to this function works fine, the SelectAuditor is initiated and then disposed of properly. On the second call the SelectAuditor is set to a new instance, and then the SelectSetup is called, which checks the disposed variable and it is false, but when the dataset event fires (code also below) and runs the SelectAudit function it checks the disposed variable and it is suddenly true, even though between the time those two functions occurred there were no other calls to any Dispose or Finalize functions. Does anyone have any idea why this might be happening? Thanks for any leads to the problem.


Aaron


Public Overloads Overrides Sub ImplementTypedDataSet(ByVal dataR As DataRequest, ByRef ds As DataSet, ByVal tableName As String, ByVal userInfo As UserInformation)


Dim sqlConn As SqlConnection
Dim sqlCmd As New SqlCommand()
Dim sqlAdapter As New SqlDataAdapter()


Try

selectAuditor = New AuditSelectSqlServer(ds.Tables, userInfo)

If selectAuditor.SelectSetup() = True Then

AddHandler ds.Tables(tableName).RowChanged, AddressOf handleSelectUpdated

Else

selectAuditor = Nothing

End If

End If



sqlAdapter.Fill(ds, tableName)

If selectAuditor Is Nothing = False Then

selectAuditor.CommitTransaction()

selectAuditor.Dispose()

End If



Catch sqlEx As SqlException

Throw New Exception("NdbDAFactory Error", sqlEx)



Catch ex As Exception

Throw New Exception("NdbDAFactory Error", ex)



Finally

sqlConn.Dispose()

sqlCmd.Dispose()

sqlAdapter.Dispose()

End Try

End Sub


Private Sub handleSelectUpdated(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)

Try

If e.Action = DataRowAction.Add Then

selectAuditor.SelectAudit(e.Row)

End If

Catch ex As Exception

Throw New Exception()

End Try



End Sub
 
Back
Top