Recordset close generates exception
Hi,
I want to create a new record within a Try Catch block using the
following code
Function Process() As Boolean
Dim rsAttendance As New clsMSRecordSet
Dim rs As ADODB.Recordset
rs = rsAttendance.recordset
Try
rs.Open("AANWREG", Conn)
rs.AddNew()
rs.Fields("ADM#").Value = mfldAttAdmID
rs.Fields("CURSUS#").Value = mfldAttCourseID
rs.Fields("EVENEM#").Value = mfldAttEventID
rs.Fields("DEELNEM#").Value = mfldAttParticipentID
rs.Fields("EV_PLN#").Value = mfldAttPlanItemID
rs.Update()
Process = True
Catch ex As System.Runtime.InteropServices.COMException
'TO DO : logging exception to xml file
Finally
If (rs.State = ADODB.ObjectStateEnum.adStateOpen)
Then rs.Close() < - generating exception
rsAttendance = Nothing
End Try
End Function
When the update fails e.g. in case of a duplicate key/record it
generates the expecting exception. However I get an other exception in
my 'finally' block
"operation not allowed in this context" when the rs.Close() is issued.
Any idea why is this happening?
I'm using VB.NET and Visual Studio 2005.
Regards,
Hans van de Laar
Date:Wed, 22 Aug 2007 00:54:11 -0700
Author:
|