Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help trapping errors

Status
Not open for further replies.

BG12424

Programmer
Jun 4, 2002
717
US
I am getting the following error when I call my WV_GetUserData function passing in a userid that does not exist in the database; however, when the userid is valid, I get the correct response.

I hope someone can help me trap this issue that I have. If there is a better way to write the code that I have, please advise. Thank you.

Error:
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/trading/brian/getUserId.asp, line 9

function WV_GetUserData(userid)

dim cmd, rs

'create ado objects
Set cmd = Server.CreateObject("ADODB.Command")
Set rs = Server.CreateObject("ADODB.Recordset")

with cmd

' set up a command object properties
.ActiveConnection = GetConnection()
.CommandText = "WVGetUserData"
.CommandType = adCmdStoredProc

'create parameters for stored procedure call
.Parameters.Append .CreateParameter("@userid",adInteger,adParamInput)

'assign values to parameters
.Parameters("@userid") = userid

'execute the command object
Set rs = .Execute
end with

'return recordset object into function name
Set WV_GetUserData = rs

'de-initialize the command object
Set cmd = Nothing

end function

<%

set rs = WV_GetUserData(900)
if rs.RecordCount = 0 then
Response.Write(&quot;No user&quot;)
else
do while not rs.EOF
Response.Write(rs(&quot;username&quot;) & &quot;<br>&quot;)
rs.movenext
Loop
end if

set rs = nothing

%> regards,
Brian
 
Try This....

If RSSendEmail.EOF then
Response.write &quot;No User&quot;
else _
Do until RSSendEmail.EOF
Response.Write rs(&quot;username&quot;) & &quot;<br>&quot;
rs.movenext
Loop
end if
 
Thanks, but that does not fix the error described above:

Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/trading/brian/getUserId.asp, line 10 regards,
Brian
 
You could turn on error handling before you execute the line of code that is giving you trouble.

on error resume next

After executing the line of code that gives an error, you just check to see if an error occurred and proceed accordingly.

You show the error that is being generated and it tells us which lines is causing trouble but I am having difficulty discerning which line that actually is. Your first error says it is line 9 and the second error says it is on line 10. Please let us know exactly which line is giving you the error.

Thanks,

Gabe
 
if rs.RecordCount = 0 then (this is the line of code that is bombing on me)

I took the advice and wrapped my logic in

On Error Resume Next

... code here ...

On Error Goto 0

and this gave me that there was &quot;No User&quot;, the result that I wanted, but is it the right way to do this? Shouldn't I get a recordcount of 0? Why does this work? Thanks

Brian regards,
Brian
 
Not entirely sure here, but if no records are found then no recordcount was ever started. Try changing to
if rs.RecordCount < 1 then Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
addendum
I think the recordcount gives a count of '-1' if nothing found Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Yes, the rs.RecordCount < 1 worked. And I removed the On Error Resume Next...On Error Goto 0. Should I do this? It's not bombing on me.

:) regards,
Brian
 
On Error... can cover a multitude of sins!
Remove it. Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Actually, now that I test a bit more, I am always getting a recordcount of -1 even when there are records in the resultset. Any ideas? Thanks

regards,
Brian
 
Remove it while you are developing but you may want to consider placing it there when you move to production.

Too many developers today care little about error handling. This is what really separates the casual developer from the professional. If you want your applications to be production strength you need to make error handling an important part of your application. If you are just starting out programming now is the time to get into the good habit of handling any errors that can pop up.

How many times have you been to a “professional” web site only to see this vb error message displayed? Not to impressive is it?! What will your users think about your site?

Thanks,

Gabe
 
It's to do with your cursor type, the default is forward only, you need a dynamic cursor Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top