Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [362]

By Root 5446 0

sqlConnectionString="server=127.0.0.1;integrated security=SSPI;" />

In particular, you need to set the mode attribute (which is case sensitive) to SQLServer and specify the connection string through the sqlConnectionString attribute. Note that the sqlConnectionString attribute string must provide credentials (user ID and password or integrated security) and a server name. However, it cannot contain tokens, such as Database and Initial Catalog, unless a custom database is enabled using allowCustomSqlDatabase, as mentioned in Table 17-8. You can specify a SQL Server Initial Catalog database name or use the SQL Server Express attachDBFileName to point to an MDB file in the connection string only if the allowCustomSqlDatabase configuration setting is enabled. If that is disabled, any attempts to specify these settings in the connection string will result in an exception.

Note

The connection string for an out-of-process session state implementation (both SQLServer and StateServer) can also be specified to refer to a connection string defined in the section. The session state module first attempts to look up a connection string from the section with the name specified in the appropriate attribute; if it is not found, the session state attempts to use the specified string directly.

As for credentials to access the database, you can either use User ID and passwords or resort to integrated security.

Note

Whatever account you use to access session state in SQL Server, make sure that it is granted the db_datareader and db_datawriter permissions at least. Note also that to configure the SQL Server environment for storing session state, administrative privileges are required, as a new database and stored procedures need to be created.

Session state in SQL Server mode supports the specification of a custom command timeout value (in seconds) to accommodate slow-responding-server scenarios. You control it through the sqlCommandTimeout attribute, as mentioned in Table 17-8.

Creating the SQL Server Data Store


You use the aspnet_regsql.exe tool to configure the database environment by creating any needed tables, stored procedures, triggers, and jobs. In general, the tool works through the command line but also offers a visual interface. It is located in the following system folder:

%Windows%\Microsoft.NET\Framework\v4.0.30319

To create the ASPState database, you must use the command line, as shown here:

aspnet_regsql.exe -S [SqlServer Instance] -E -ssadd -sstype p

The tables that get created are named ASPStateTempApplications and ASPStateTempSessions. Figure 17-5 shows a view of the session database in SQL Server.

Figure 17-5. The ASPState database in SQL Server Enterprise Manager.

The ASPStateTempApplications table defines a record for each currently running ASP.NET application. The table columns are listed in Table 17-9.

Table 17-9. The ASPStateTempApplications Table

Column

Type

Description

AppId

Int

Indexed field. It represents a sort of autogenerated ID that identifies a running application using the SQLServer session mode.

AppName

char(280)

Indicates the application ID of the AppDomain running the application. It matches the contents of the AppDomainAppId property on the HttpRuntime object.

The ASPStateTempSessions table stores the actual session data. The table contains one row for each active session. The structure of the table is outlined in Table 17-10.

Table 17-10. The ASPStateTempSessions Table

Column

Type

Description

SessionId

Char(88)

Indexed field. It represents the session ID.

Created

DateTime

Indicates the time at which the session was created. It defaults to the current date.

Expires

DateTime

Indicates the time at which the session will expire. This value is normally the time at which the session state was created plus the number of minutes specified in Timeout. Note that Created refers to the time at which the session started, whereas Expires adds minutes to the time

Return Main Page Previous Page Next Page

®Online Book Reader