10 Aug 2011

Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed

Setting up a new MVC 3 (ASP.NET 4) site, using SQL Session State. Got the message:

Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed on the SQL server

But I *had* set up Session State, so this was perplexing.

Turns out this was because I had only given the ASP.NET user db_datareader and db_datawriter permissions on the Session State database. Those permissions don't allow the user to EXEC sprocs. I gave the user db_owner perms and all was well.

Stupid unhelpful error message!

Linq select vs Enumerable.Select()

I found the MSDN docs a bit confusing with this, so here's a brief aide memoire about how to transform a list of one Type to a list of another, using Linq and also Enumerable Linq methods.

In this case I'm transforming from a List of EF Entities (called promotions here) to a list of MVC SelectListItems.

Standard Linq stylee

var query = from promo in promotions
select new SelectListItem { Text = promo.Name, Value = promo.Id.ToString() };

Enumerable Linq Method stylee


var query = promotions.Select(promo => new SelectListItem() { Text = promo.Name, Value = promo.Id.ToString() });

To get a List out, you just do query.ToList().
If I helped you out today, you can buy me a beer below. Cheers!