Re: Closing recordset generates exception
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Wed, 22 Aug 2007 11:08:29 -0400
Hans van de Laar wrote:
Hi,mfldAttParticipentID
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 =
rs.Fields("EV_PLN# ").Value = mfldAttPlanItemIDI think if you inspect the rs.State property during debugging you may
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 I get a descriptive message but I an other error
"operation not allowed in this context" is thrown up when the
rs.Close() is issued. Any idea why is this happening?
I'm using VB.NET and Visual Studio 2005
get more of a clue. A recordset's state can be a combination of
ObjectStateEnum values ...
http://msdn2.microsoft.com/en-us/library/ms675068.aspx
I share Stephen's concern with the "AANWREG" given that you are not
specifying the CommandType setting in the Open statement. Given the lack
of a syntax error, It seems that ADODB is correctly interpreting it and
using adCmdTable, but, for this operation (inserting a record), you
should probably be using a sql statement that does not return any rows.
Something like:
Dim sql as string = "Select ADM#, CURSUS#,EVENEM#, " & _
"DEELNEM#,EV_PLN# FROM AANWREG WHERE 1=2"
rs.Open(sql,conn,,,,1) '1=adCmdText
'etc.
Personally, I would not be using a recordset for this operation: just
execute a simple parameterized SQL INSERT statement using a Command
object (why are you insisting on using classic ADO anyways?)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- Follow-Ups:
- Re: Closing recordset generates exception
- From: Hans van de Laar
- Re: Closing recordset generates exception
- References:
- Closing recordset generates exception
- From: Hans van de Laar
- Closing recordset generates exception
- Prev by Date: Re: Closing recordset generates exception
- Next by Date: Re: Closing recordset generates exception
- Previous by thread: Re: Closing recordset generates exception
- Next by thread: Re: Closing recordset generates exception
- Index(es):
Relevant Pages
|
|