Exforsys

Online Training

whats the Use of Storing Sessions external to InProc?

This is a discussion on whats the Use of Storing Sessions external to InProc? within the Microsoft .NET forums, part of the Programming Talk category; Hai, Can any one clarify whats the difference in storing Sessions externally that storing in Inproc. whats the difference between ...


Go Back   Exforsys > Programming Talk > Microsoft .NET

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-08-2006, 02:15 PM
Junior Member
 
Join Date: Jan 2005
Posts: 2
srinivaasu
whats the Use of Storing Sessions external to InProc?

Hai,
Can any one clarify whats the difference in storing Sessions externally that storing in Inproc. whats the difference between SqlServer and StateServer and in what cases we use them?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-08-2006, 09:07 PM
Junior Member
 
Join Date: Apr 2006
Posts: 25
Limca is on a distinguished road
difference between SqlServer and StateServer

StateServer

StateServer is a service which is off by default. You can enable it by going into "Administration" --> "Services" and right-clicking on "ASP.NET State Service" (go to Properties and select "automatic" if you want it to start when Windows starts). When your sessionState is in StateServer, sessions aren't stored in the ASP.NET worker-process, which avoids the worker process recycle problem. Additionally, two or more separate web servers can access a single StateServer, meaning session state will automatically be shared across a web farm.

There are two very important things to keep in mind when using StateServer. Firstly, it isn't as fast as having the data stored directly in the ASP.NET worker process. This can be easily resolved by smarty using the HttpCache class. Secondly, data stored in the StateServer must be serializable. Strings, ints and most built-in types are mostly all automatically serializable. Custom classes can typically be marked by the System.SerializableAttribute attribute:

[Serializable()]
public class User {
private int userId;
private string userName;
private UserStatus status;

public int UserId {get { return userId; } set { userId = value; }}
public string UserName {get { return userName; }set { userName = value; }}
public UserStatus Status {get { return status; }set { status = value; }}

public enum UserStatus {
Invalid = 0,
Valid = 1
}
}

To use StateServer, you must specify both the SessionState mode, as well as the address of the StateServer via stateConnectionString. StateServer runs on port 42424 by default, so the example below connects to the state server on the local machine.

stateConnectionString="tcpip=127.0.0.1:42424" />

SQL Server

Using SQL Server is much like using StateServer. Both require data to be serializable, both are overall slower (but won't cause the entire app to have performance issues), and both can be accessed by multiple web servers. The difference between the two is, well obviously, one uses the StateServer service while the other uses SQL Server. This has pretty wide implications. By storing your sessions in SQL Server, you can take advantage of multiple databases, load balancing, and fault-tolerance. You also have to pay big money for it.

Enabling SQL Server is much like StateServer: set the mode to SQLServer and specify the connection via the sqlConnectionString attribute:

stateConnectionString="Initial Catalog=Session;server=localhsot;uid=sa;pwd=;" />

Additionally, you must run a script to create the database. This script is located in system drive\WINNT\Microsoft.NET\Framework\version\InstallSqlState.sql, for example: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallSqlState.sql on my computer (Windows instead of WinNT because I'm using XP). Simply run it, and you're ready to go.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:21 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.