Operation Is Not Allowed When The Object Is Closed!

A

Arpan

An ASP application updates a SQL Server database table after a Form is
submitted after which the user is directed to another page that should
display the updated records. If the code is

----------------------------------------
'records get updated here
Response.Redirect("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the user is correctly shown the updated records after redirection.
If the code is

----------------------------------------
'records get updated here
Server.Transfer("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the updated records aren't reflected. The updated records can be
seen only after refreshing the page. If the code is

----------------------------------------
'records get updated here
Server.Execute("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the "Operation is not allowed when the object is closed" error
gets generated though the records in the table get updated.

If any of the 3 Response.Redirect or Server.Execute or Server.Transfer
lines are placed after closing the recordset object & the connection
object, again the above error gets generated though the records in the
database get updated successfully in each of the 3 cases. What causes
the above mentioned error & the difference in the output displayed?

Thanks,

Arpan
 
J

Jeff Cochran

An ASP application updates a SQL Server database table after a Form is
submitted after which the user is directed to another page that should
display the updated records. If the code is

----------------------------------------
'records get updated here
Response.Redirect("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the user is correctly shown the updated records after redirection.
If the code is

----------------------------------------
'records get updated here
Server.Transfer("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the updated records aren't reflected. The updated records can be
seen only after refreshing the page. If the code is

----------------------------------------
'records get updated here
Server.Execute("Records.asp")

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
----------------------------------------

then the "Operation is not allowed when the object is closed" error
gets generated though the records in the table get updated.

If any of the 3 Response.Redirect or Server.Execute or Server.Transfer
lines are placed after closing the recordset object & the connection
object, again the above error gets generated though the records in the
database get updated successfully in each of the 3 cases. What causes
the above mentioned error & the difference in the output displayed?

The cause is the fact that you don't understand what happens in a
Server.Redirect, Server.Transfer or Server.Execute. Google for
tutorials on those. Don't close a recordset on a page that didn't
open them (poor programming) .

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top