cookie question

M

middletree

I use a browser cookie on an Intranet application. On one certain page, it
checks to see what someone's network name is, then if they are in a certain
department, it redirects them to a particular page. If in other departments,
it redirects them to another page.

Here's the code:

===================================

strLogon= UCASE(Request.ServerVariables("LOGON_USER"))

Set RS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT EmployeeID, DepartmentID "
strSQL = strSQL & "FROM Employee "
strSQL = strSQL & "WHERE NetworkID = '"&strLogon&"'"

RS.Open strSQL, objConnection

'this is to pass the value of the name of the TSE to the next page
Response.Cookies("TSE_ID") = rs("EmployeeID")
strDepartmentID = rs("DepartmentID")
strEmployeeID = rs("EmployeeID")
rs.Close
Set rs = Nothing

If strDepartmentID = "9" then
Response.Redirect("DisplaySortableTickets.asp?selectTSE="&strEmployeeID&"")
Else
Response.Redirect("DisplaySortableTickets.asp?AssistEmp="&strEmployeeID&"")
===================================
For some reason, every now and then, I get this in the browser:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'RS(...).Cookies'
yourticketsredirect.asp, line 22

I have checked and according to the network people, they have not made any
changes. In fact, this error usually goes away in a few minutes. Any
suggestions, comments, or insights to share?
 
R

Ray Costanzo [MVP]

What line is line 22? One of the redirect lines?

What happens if you change

strDepartmentID = rs("DepartmentID")
strEmployeeID = rs("EmployeeID")

to

strDepartmentID = rs.Fields.Item("DepartmentID").Value
strEmployeeID = rs.Fields.Item("EmployeeID").Value

?

Ray at work
 
M

middletree

Ray:

Yes, sorry I forgot to say which was line 22. Here it is:

Response.Cookies("TSE_ID") = rs("EmployeeID")

I can change that code, but since this problem happens so sproadically and
unpredictably, I'll just have to see what happens.

I do realize that having ".Fields.Item" is better form, but didn't realize
that it caused problems.
 
R

Ray Costanzo [MVP]

I've heard comments before about how rs("name") returns an object with a
default property of the item's value, but I can't find anything to back that
up. From the error you posted I thought it ~~might~~ have something do do
with that. But, really, it's probably not that likely.


Does this work?

<%
sTest = rs("EmployeeID")
Response.Write "The value is " & sTest
Response.Cookies("TSE_ID") = sTest
%>

Ray at work
 
B

Ben Strackany

My guess is rs("EmployeeID") is sometimes null or doesn't exist. Add some
code to check recordcount & check

if ("" & rs("EmployeeID")) = "" then
' blank EmployeeID, handle it somehow
end if
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top