Search KB Filter article types
Serialization - Setting up an SQL state database on SQLServer Express
Categories: State Serialization, Scalability
Tags: Architects, Developers, Visual WebGui Pipeline, 2. Intermediate, 3. Advanced, Optimizing Performance, v6.4 and Later
Revision: 1
Posted: 09/Dec/2009
Updated: 24/May/2010
Status: Publish
Types: Walkthrough

Overview

This article will walk you through how to set up a new database on Microsoft SQLServer Express, and how to adjust your Visual WebGui application's web.config to use that database for serializing and storing it's state.

The same procedure will work for other flavors of SQLServer, apart from some specifics that only apply to SQLServer Express.

Security

Please note that this walkthrough demonstrates one way of creating and using the state database on SQL Server, but as we save SQL user and password in web.config's connection string, you should gather information on alternative means of authentication that follow your standards, before you deploy a production or public application state database.

Preparing the SQLExpress server
Allow SQL logins to the server

Depending on your initial setup of the SQLExpress server, you may need to allow SQL server logins to the server, in addition to Windows Authentication logins.

Using the Management Studio (Microsoft SQL Server Management Studio Express), right click on the Server and enter Properties. On the Security tab, make sure the Server authentication is set for SQL server and Windows authentication mode.

Create a SQL user

We will be using a SQL user in a connection string in our web.config, so make sure you have an SQL user created.

In this walkthrough, we will create a new user ASPstateUser with the password ASPstatePW.

Using the Management Studio, you create that user under the Security\Logins.


Create a SQL database

the Management Studio, create a new SQL database. The default database name for a stateserver in ASP.NET (and hence Visual WebGui) application is ASPState, but to break the defaults and show you how you set all the properties, we will name our database ASPSateDB.

When you create the database, the most easy way to grant enough security to the ASPStateUser, would be to designate that user as the database owner. Again, we will not do that, and we specifically grant the necessary rights later.

For now, simply create the ASPStateDB, and leave the database owner at default.

Adjust user settings

that we have both the user and database in place, we can adjust the ASPStateUser's settings.

Opening our ASPStateUser's properties, in the User Mappings tab, our user must be granted the db_datareader and db_datawriter roles for the ASPStateDB database.

At this point we choose the easy way out and grant our user the db_owner role, but you can of course hunt down what access needs to be granted to this user as a minimum and set that accordingly.

In addition, make sure the user's default database (in General tab) is set to our ASPStateDB.

Build the database schema

Included with the .NET framework is a aspnet_regsql.exe utility that will automatically build the database tables necessary for the database to act as a state database.

You will need to open a command window on the server, and make sure that command window is running with administrative rights.

With an open command window, run the following commands:

cd C:\Windows\Microsoft.NET\Framework\v2.0.50727

aspnet_regsql.exe -S .\sqlexpress -E -ssadd -sstype c -d ASPStateDB

  • -S .\sqlexpress - the SQL server and instance you connect to. In this case we connect to localhost and the instance name is sqlexpress
  • -E - we use integrated authentication for the aspnet_regsql to connect to the database. We are already running in a command window with admin privileges.
  • -ssadd - Add support for SQLServer mode session state
  • -sstype c - Both session state data and stored procedures will be stored in custom database you specify (as we will do in web.config).
Adjust web.config

The final step in the process is to adjust the web.config settings for using stateserver, instead of the default "InProc" sessionState mode for Visual WebGui applications.

According to our parameters above in the article, we change our sessionState to

<sessionState 
    mode="SQLServer" 
    allowCustomSqlDatabase ="true" 
    sqlConnectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPstateDB;User Id=ASPStateUser;Password=ASPSatePW;" 
    stateNetworkTimeout="15" />

  • mode="SQLServer" - this is what activates the stateserver
  • allowCustomSqlDatabase ="true" - needed to be able to specifically adjust the database settings
  • sqlConnectionString - a normal SQL connection string
  • stateNetworkTimeout="15" - Number of seconds until a request to the stateserver times out.
References
Forum discussions

About the author

Related Articles

State Serialization  
Title Update Author
Tags: Architects, Developers, Visual WebGui Pipeline, 2. Intermediate, 3. Advanced, Optimizing Performance, Pre v6.3, v6.3, v6.4 and Later
10/Dec/2010    2010/12/10
Tags: Architects, Developers, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Developers, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
23/July/2010    2010/07/23
Tags: Developers, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
24/Nov/2010    2010/11/24
Tags: Developers, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
22/Nov/2010    2010/11/22
Tags: Developers, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
23/July/2010    2010/07/23
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS