Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6328659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:29:57+00:00 2026-05-24T17:29:57+00:00

I’m using EF4.1 in code-first style to persist POCO objects for a small ASP.NET

  • 0

I’m using EF4.1 in code-first style to persist POCO objects for a small ASP.NET MVC 3-based webapp in an SQL Azure DB ‘MyAppsDB’. The tables are automatically created in MyAppsDB when they don’t exist. I’d like to host the app on SQL Azure, but I don’t want to pay $10/mo for an extra 1GB DB to store 50MB of session state, and using Cache would be even more expensive.

I’d like to store session state in MyAppDB along with my app’s models. Is there a way to do this?
Can I have the Session table auto-created if it doesn’t exist, same as EF code-first models?

I’ve tried modifying my web.config as follows:

<sessionState mode="Custom" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      connectionStringName="MyAppDBContext" applicationName="/" />
  </providers>
</sessionState>

But it complains the session table doesn’t exist. If I create the session table, EF4.1 complains that the DB metadata doesn’t match its expectations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:29:58+00:00Added an answer on May 24, 2026 at 5:29 pm

    It’s certainly possible to use your existing SQL Azure database for session state. I’m doing exactly that (and for exactly the same reason). The standard scripts don’t work, as they’re not compatible with SQL Azure. There are some updated scripts somewhere (I can’t remember where, but I’ll have a Google around) that I used to set up the DB.

    It’s not code-first, though. You may be able to reverse-engineer the schema, but there are a number of stored procs involved.

    Note that you’ll also want to think about tidying up expired sessions. There’s a stored procedure that needs running periodically (DeleteExpiredSessions, I think) and the typical recommendation is to run it from a Worker Role. But you won’t want to deploy a Worker Role for the sole purpose of running a stored procedure periodically!

    Edit: Found the script on this page. Note that there’s an issue with the script posted in the main article, but there’s a modified script further down the page in a comment from Peter McEvoy.

    Some recommend use of an Azure Table Storage session state provider in preference and if I wasn’t using SQL Azure already, I’d be inclined to agree. But I’ve had problems with the Azure provider (particular in the dev environment) but have had no problems at all using SQL Server Session State once the updated scripts are deployed.

    Edit 2: I’ve made further progress and I’ll write it up for my blog and post a link here.

    Highlights, though are:

    • Run the InstallSqlState.SQL script (the modified one for Azure) against an empty database
    • Use EF Power Tools to reverse-engineer the ASP State Tables into EF Code-First
    • Integrate the reverse-engineered classes into your model and context
    • Modify the mapping for the ASPStateTempSessions table to use an Image column type
    • Create a new SQL Script from InstallSqlState.SQL that just creates the stored procs
    • Modify the stored procs to always specify default values
    • Add some code to run the SQL Script in the Initializer Seed() method

    I think that’s about it, but I’ll give a more complete description on my blog when I’ve written it up.

    Edit 3:

    Part I of my write-up is now on my blog. Part II coming soon (but time for bed, now).

    Edit 4:

    Part II is also written, now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.