Forum Moderators: open
But as soon as I create a session it dies? What is with sessions in ASP?
error '80020009'
Exception occurred.
/WCABHeader.asp, line 27
================ here is the working/not working code:
<%if Session("Bemms") = "" then%><A href="SignIn.asp">Sign-In</a><% elseif Session("Access") = "Admin" then%>- Admin "On"<% end if %>
thanks!
Session("Bemms") is blank you're not running the problem code, but when it isn't blank you're running Session("Access") = "Admin" which is what you reported as generating this error the other day [webmasterworld.com]... Since it's all on the one line it's hard to say if it's the "if" clause or the "elseif" that's the cause of the problem, breaking the statements onto different lines should probably be your first step.
If it is still the
Session("Access") causing this problem then I'd suggest looking at how you're populating it ... off the top of my head I think I've seen similar problems when you store an object in a session and then try to compare that object to a string directly (but don't quote me on it). - Tony
isnull did work for the First session but now I need to check the contents of the second session var (the one above).
as for how they are getting set:
Set TrySignIn = MyConn.Execute(SQL_QUERY)
if TrySignIn("Access") <> "" then
Set Session("Access") = TrySignIn("Access")
Set Session("Bemms") = TrySignIn("Bemms")
end if
and I have tried:
Set Session("Access") = cstr(TrySignIn("Access"))
but it does not work.
Thanks - really Many Thanks!
Set TrySignIn = MyConn.Execute(SQL_QUERY)
if TrySignIn("Access") <> "" then
Set Session("Access") = TrySignIn("Access")
Set Session("Bemms") = TrySignIn("Bemms")
end if
Once you place an object into a variable you can't treat it like it's a string and expect it to work (even if it does work it's still a bad habit), that's probably what's generating your exception.
In this case your problem is that you're using SET to put the field object rather than then field contents into the session variable which is probably why it chokes when doing a string comparison.
So how do you fix this? Well the first problem is that you're using SET when it looks like you just want string data, so lose the SETs. The second problem two is that you're using the default property on the field array, it's safer to explicitly request the field value (.value) because then you know what you're getting.
That should leave you with something like;
Set TrySignIn = MyConn.Execute(SQL_QUERY)
if TrySignIn("Access").value <> "" And Not IsNull( TrySignIn("Access") ) then
Session("Access") = TrySignIn("Access").value
Session("Bemms") = TrySignIn("Bemms").value
end if
On the other hand if you did want to check if a variable contains an object then the way to do it is via
IsObject rather than checking if the variable is not equal to a blank string. - Tony
When I set the session properly: ".value" then everything starts to work:
Check for Admin:
if Session("Access") = "Admin" then%>- Admin "On"<% end if %>
Check for not login:
if Session("Bemms") = "" then%>
perfect! many thanks!
a couple of tutorials and examples and I have converted an entire CF app in only a few days!