When mixing code from several different sources, you may come across this error:
Microsoft VBScript runtime error '800a01a8' Object required: '' /<file>.asp, line <line>
|
This is usually because you've tried to close or set to nothing an object that hasn't been defined. To reproduce, try this code:
<% set conn = CreateObject("ADODB.Connection") conn.open <connection string> ' ... objConn.close set objConn = nothing %> |
Another common cause is using the SET keyword to create a string, most often a SQL statement, e.g.
| SET sql = "SELECT bar FROM foo" |
Which leads to the following:
Microsoft VBScript runtime (0x800A01A8) Object required: '[string: "SELECT bar FROM foo"]' |
Another possible cause is using a reserved object name as a variable name. For some reason, ASP lets you do this:
However you will get the above error if you do this:
<% dim response response.redirect("http://www.foo.com/") %> |
But oddly enough, not when you do this:
<% dim response response.write("http://www.foo.com/") %> |
The line number in the error message should make it fairly easy for you to track down which object's name you've messed up. My advice is to always open late, close early... close your objects as soon as you're finished with them. But if you have sloppy code that doesn't keep track of its objects, or you are using a catch-all at the bottom of the page, how do you prevent these errors? You can check if the object exists by using the isObject() function:
<% if isObject(objectName) then set objectName = nothing end if %> |
If the object has open/close methods, you can also check their state to see if they're open, and make sure that you close them properly. This can be done, for example, with recordset and connection objects:
<% const adStateOpen = 1 if not (rs is nothing) then if rs.state = adStateOpen then rs.close set rs = nothing end if %> |