Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: Cannot Use Null Key Values for Session Variables in SQL Server Mode or State Server Mode


View products that this article applies to.

This article was previously published under Q321023

↑ Back to the top


Symptoms

If you use null key values for session variables in the State Server session state mode or SQL Server session state mode in ASP.NET, you receive the following error message:
Server Error in '/SessionNullKB' Application.
Value cannot be null. Parameter name: value

Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: value

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in ASP.NET (included with the .NET Framework) 1.1.

↑ Back to the top


More information

Microsoft recommends that you not use null key values for session variables.

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual C# Projects under Project Types, and then click ASP.NET Web Application under Templates.
  4. Add the following code in the code-behind file (WebForm1.aspx.cs) in the Page_Load event handler:
    Session[null]="testSession";
    					
  5. In the Web.config file, modify the mode attribute in the <sessionState> element to use SQL Server or State Server mode. Make sure that the user id account has permissions on the database. For example:
    <sessionState 
                mode="SQLServer"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<password>"
                cookieless="false" 
                timeout="20" 
    />
    						
    -or-
    <sessionState 
                mode="StateServer"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strong password>"
                cookieless="false" 
                timeout="20" 
    />
    						
    NOTE: To use State Server session state mode, you must start the ASP.NET state service. To use SQL Server session state mode, you must configure Microsoft SQL Server for this purpose.
  6. Build the project.
  7. Open the WebForm1.aspx page in your browser. You receive the error message that is listed in the "Symptoms" section.

↑ Back to the top


References

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
307598� INFO: ASP.NET State Management Overview

↑ Back to the top


Keywords: KB321023, kbstate, kbconfig, kbbug, kbfix

↑ Back to the top

Article Info
Article ID : 321023
Revision : 6
Created on : 1/19/2004
Published on : 1/19/2004
Exists online : False
Views : 414