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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning an Application object as a dictionary?

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
I have one application object that keeps track of how many users are logged onto my site at any given time, however I want to develope a script to list all of the user's names or ID's that are currently logged on for everyone to see who's on the site with them at the same time. (small site...200 or less people)

I tried assigning an application object as a scripting dictionary to load the user's name to the list as they log in, and then when the session ends it'd take their name out of the list...but getting this error on a test page...

Application object error 'ASP 0197 : 80004005'

Disallowed object use

/user.asp, line 13

Cannot add object with apartment model behavior to the application intrinsic object.


Anyone have any ideas? Here is my code for the test page...once it's working I will tweak it to use within the site...


<% @ Language=VBScript %>
<% Option Explicit %>
<form action=&quot;<%= Request.ServerVariables(&quot;Script_Name&quot;)%>&quot;>
User: <input type='text' name='user'>
<BR><BR>
<DD><input type='submit' value='Submit'>
</form>

<%
Dim user
user = Trim(Request.QueryString(&quot;user&quot;))
If Len(user) > 0 Then
If IsEmpty(Application(&quot;userList&quot;)) Then
Set Application(&quot;userList&quot;) = Server.CreateObject(&quot;Scripting.Dictionary&quot;)
End If
Dim localUsers
Set localUsers = Application(&quot;userList&quot;)
localUsers.Add CStr(localUsers.Count+1),user
End If
%>


Thanks in advance for any help you can offer! -Ovatvvon :-Q
 

Can't be stored as an object but read all the properties and methods.
'.............
Dim aryItems
Dim aryKeys
' Store
Application(&quot;Items&quot;) = dctd.Items
Application(&quot;Keys&quot;) = dctd.Keys
'
&quot; Restore
dctd.Items = Application(&quot;Items&quot;)
dctd.Keys = Application(&quot;Keys&quot;)
For I = 0 To Ubound(aryItems)
dctd(aryKeys(I)) = aryItems(I)
Next
'
Compare Code (Text)
Generate Sort in VB or VBScript
 
Heh, funny thing is according to the site listed, when VB6 is installed it's supposed to fix the problem. But mine is installed with SP5 and it doesn't seam to be fixed. The even more funny thing is their work-around. Set all scripting.dictionary objects with a session scope. Well, there's a reason for the application scope which is why I was using it...if I wanted the session results I'd have used the session from the get-go. Microsoft!

Eh,
well, does anyone have any logical suggestions of how to make it work? Anyone else worked on a similar task?
-Ovatvvon :-Q
 
Read that again.
&quot;CAUSE
The Dictionary object's threading model is incorrectly set to &quot;Both&quot; in the registry when Internet Information Server (IIS) 4.0 is initially installed. This is documented in the IIS documentation, which also includes instructions to update the ThreadingModel registry key. When Visual Studio 6.0 is installed it updates/corrects the threading model of the Dictionary object, setting it to &quot;Apartment.&quot;

Thus you get an error because the dictionary's threading model is now set correctly and can not be stored in the Application object.
Compare Code (Text)
Generate Sort in VB or VBScript
 
hmm, I find that rather inferior. Why would they specifically design it to not run in the application object?

Can you think of any other solutions to accomplish this task? -Ovatvvon :-Q
 
I one I gave you is the only one I ever figured out.

By the way. You'll have to use Application.Lock and .Unlock from the time you get the data from the Application object until you put it back into it unless you do not care about losing some data when an instance 1 gets data before instance 2 and then puts it back after instance 2 has stored its data back.

That locking is going to &quot;single thread&quot; your application for the time that it is locked and others want the lock. Compare Code (Text)
Generate Sort in VB or VBScript
 
I figured out a good way to do it...
----------------------------------------


<%
' Adding the users to the list within the login page

Dim user
user = rs(&quot;user&quot;)

session(&quot;user&quot;) = user
Application(&quot;users&quot;) = Application(&quot;users&quot;) & &quot; &quot; & user
Application(&quot;users&quot;) = Trim(Application(&quot;users&quot;))
%>


<%
' Displaying the users on the display page

If not IsEmpty(Application(&quot;users&quot;)) Then
Dim userList
userList = Split(Application(&quot;users&quot;),&quot; &quot;)
For i = 0 to UBOUND(userList)
Response.write(userList(i) & &quot;<BR>&quot;)
Next
End If
%>


Global.asa = To take the user off the list

-------------------------------------------

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnEnd
Application(&quot;users&quot;) = Replace(Application(&quot;users&quot;), session(&quot;user&quot;), &quot;&quot;)
Application(&quot;users&quot;) = Replace(Trim(Application(&quot;users&quot;)), &quot; &quot;, &quot; &quot;) 'Replaces double spaces with a single space
End Sub
</SCRIPT>

-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top