This project is read-only.

SQL Server 2014 In-Memory OLTP Provider - ASP.NET

Rating:        Based on 2 ratings
Reviewed:  2 reviews
Downloads: 1708
Released: Jul 9, 2014
Updated: Jul 10, 2014 by DerrickVMSFT
Dev status: Stable Help Icon


Source Code
source code, 19K, uploaded Jul 10, 2014 - 1708 downloads

Release Notes

Apache License, Version 2.0

This content contains the source code developed for ASP.NET to take advantage of SQL Server 2014 In-Memory OLTP as a session state store. The zip file contains source code for an optimized ASP.NET Provider for In-Memory OLTP. It also contains .sql scripts to create memory-optimized tables and natively compiled stored procedures in SQL Server for further performance gains.

The source code is provided for reference here. A downloadable package for deployment is also available via NuGet:

Get Started

Setting up the provider requires two steps, installing the provider into the ASP.NET application and creating the In-Memory OLTP database and objects in Microsoft SQL Server 2014.

NuGet Installation

Download the ASP.NET Session State Provider for SQL Server In-Memory OLTP from the NuGet gallery by running the following command from the Visual Studio Package Manager Console:

PM> Install-Package Microsoft.Web.SessionState.SqlInMemory

Installing the package will do the following things:

• Add references to the ASP.NET Session State Provider assembly.
• Add to the web.config file a customProvider equals to "SqlInMemoryProvider", where the connectionString attribute needs to be updated.

<?xml version="1.0" encoding="utf-8"?>
    <sessionState mode="Custom" customProvider="SqlInMemoryProvider">
        <add name="SqlInMemoryProvider"
             connectionString="data source=sqlserver;initial catalog=ASPStateInMemory;User ID=user;Password=password;" />

• Adds an ASPStateInMemory.sql file that includes the script for creating the SQL Server database configured to support In-Memory OLTP.

Setting up In-Memory OLTP Database and objects

Open the T-SQL script file "ASPStateInMemory.sql" and update the 'CREATE DATABASE' statement to replace the 'FILENAME' attributes to specify a path that will exist in your SQL Server machine where the memory-optimized filegroup should exist. For further considerations on placement of this filegroup, see Books Online section Creating and Managing Storage for Memory-Optimized Objects.

NAME = ASPStateInMemory, FILENAME = 'D:\SQL\data\ASPStateInMemory_data.mdf'
NAME = ASPStateInMemory_xtp:, FILENAME = 'D:\SQL\data\ASPStateInMemory_xtp'

After updating the 'FILENAME' attributes, run the entire script for creating the In-Memory tables and the natively compiled stored procedures.

Additionally, create a periodic task in SQL Server to run the stored procedure 'dbo.DeleteExpiredSessions'. This procedure removes the expired sessions and frees up the memory consumed.

NOTE: The memory-optimized tables are created with a durability of SCHEMA_ONLY to optimize for performance. If session data durability is required, then change the 'DURABILITY' attribute from 'SCHEMA_ONLY' to 'SCHEMA_AND_DATA'. More information can be found in Books Online sections Defining Durability for Memory-Optimized Objects and Durability for Memory-Optimized Tables.

Reviews for this release

Poor simply because the code is not in this repository, and there have been no updates in forever. There is a non-custom session provider implementation here: Seems to be the better route, SQL2016 with retry.
by djbyter on Feb 3, 2017 at 8:26 PM
Hi, could you please post V 1.0.2 Source code. Unfortunately, my apps are still running under V4.0. I need to rebuild and generate dll to run against v4.0 .net framework. Thanks for your help.
by samtel143 on Jul 2, 2015 at 9:46 PM