How to use ASP.NET session state SQL Server Mode in a failover cluster (323262)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework 1.1)
- Microsoft ASP.NET (included with the .NET Framework) 1.0
This article was previously published under Q323262 SUMMARYThis article describes the information that you must have to configure a Web server cluster to use the SQL session state that runs in a failover cluster. If you anticipate many requests on your Microsoft ASP.NET applications, you may install a Web farm of Web servers that are running on Windows Network Load Balancing (WNLB).
By using WNLB, you can reveal a virtual access point to your users. WNLB shares the workload across all members of the Web farm transparently. If your Web application uses a session, you can store the ASP.NET session state in SQL Server to gain more reliability and to improve virtual access for the users. MORE INFORMATIONASP.NET offers significant versatility in saving a session
state. This solves most problems that may occur while you run earlier ASP
applications in a Web farm. You can configure the Web.config file of a particular application to use the SQL session state on a failover cluster. Microsoft SQL Server offers you
centralized storage of a session state in a Web farm. It also offers the
transactional capabilities that provide reliability to most relational database
systems. You can use SQL Server to save a session.
Configure ASP.NET to store session state in SQL ServerWhen
you set the value of the mode attribute to SqlServer in the sessionState element of the Web.config file, an ASP.NET worker process stores
the objects that belong to the
client session collection in SQL Server at the end of
each Web request.
For additional information about how to install SQL session state in a SQL Server cluster, click the following article number to view the article in the Microsoft Knowledge Base:
311209
How to configure ASP.NET for persistent SQL Server session state management
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
317604
How to configure SQL Server to store ASP.NET session state
To store the ASP.NET session state in SQL Server,
change the <sessionState> element in the Web.config file as follows:
<configuration>
<system.web>
<sessionState mode="SQLServer"
sqlConnectionString="data source= ServerName;
user id=User;password=Password"
cookieless="true"
timeout="20" />
</system.web>
</configuration>
Note Verify that you use the correct case when you specify the <sessionState> element and the associated attribute values. This code is case
sensitive. Sample application for testing- Use Visual C# .NET to create a new ASP.NET Web
Application named ASPNETSession.
- In HTML view of WebForm1.aspx, replace the existing code with the following code:
<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 23px; POSITION: absolute; TOP: 38px"
runat="server"></asp:TextBox>
<asp:Button OnClick="Button1_Click" id="Button1" style="Z-INDEX: 104; LEFT: 190px; POSITION:
absolute; TOP: 37px" runat="server" Text="Set Session Value"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 75px"
runat="server" Width="153px" Height="21px" BorderColor="#C04000" BorderStyle="Solid"
BorderWidth="1px"></asp:Label>
<asp:Button OnClick="Button2_Click" id="Button2" style="Z-INDEX: 102; LEFT: 190px; POSITION:
absolute; TOP: 75px" runat="server" Text="Get Session Value"></asp:Button>
</form>
</body>
</HTML>
<script runat=server>
private void Button1_Click(object sender, System.EventArgs e)
{
Session["myval"]=TextBox1.Text;
}
private void Button2_Click(object sender, System.EventArgs e)
{
Label1.Text=Session["myval"].ToString();
}
</script>
- Compile and then run the application.
Note Make sure that the Web farm of Web servers is set up, and that
SQL Server Services are started before you run the Web application. - Type any string in the first text box, and then click
Set Session Value.
- The session state is stored in SQL Server with a unique session ID. Examine the session state that is stored in the ASPStateTempSessions table of the ASPState database.
- Stop the first Web Server that your request is processed
from.
- In the browser, click Get Session
Value.
- Note that the string that is stored in the session by the
first Web server appears in the text box although the first Web server is
stopped. The second Web server runs the service for the request.
Note Because of a bug in the System.data.dll file in the Microsoft .NET Framework 1.0 and the .NET Framework 1.1, SqlConnections that were connected to the old (now stopped) SQL Server-based server will still be kept in the connection pool. Therefore, you may see some errors in the request because ASP.NET is still using those dead connections in a browser. But when all these pooled dead connections are used and discarded, it will start working again. REFERENCES
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
307598
ASP.NET state management overview
312906 How to create keys by using Visual C# .NET for use in Forms authentication
313091 How to create keys by using Visual Basic .NET for use in Forms authentication
Modification Type: | Major | Last Reviewed: | 11/16/2004 |
---|
Keywords: | kbDatabase kbWebServer kbWebForms kbNLB kbClustering kbinfo KB323262 kbAudDeveloper kbAudITPRO |
---|
|