Universal ASP.NET Providers??? Getting SQL Azure to handle your Session State


While pulling together this post on the August release of the Windows Azure Tools I noted that the ASP.NET MVC 3 template included “the new universal ASP.Net providers that support SQL Azure”. Which made me pause and think … “What universal ASP.NET Providers?”

Looks like their existence completely passed me by 🙂

Scott Hanselman summarised the purpose of the Universal Providers back in June. Simply put they extend Session, Membership, Roles and Profile support to include SQL Compact Edition and SQL Azure. In all other ways they work like the existing SQL-based providers. They are released via a NuGet Package (something else I need to dig into more).

What this means is we now have a supported way of doing session state with SQL Azure, rather than via workarounds (e.g. this one from Wayne)

By default, the NuGet package sets the connection string to use a SQL Server Express database:

"Source=.\SQLEXPRESS;

AttachDbFilename=|DataDirectory|\aspnetdb.mdf;

Initial Catalog=aspnet;

Integrated Security=True;

User Instance=True;

MultipleActiveResultSets=True" 

providerName="System.Data.SqlClient" 

For SQL Azure you simply change to:

“data source=myDNSName;

Initial Catalog=myDatabase;

User ID=myUserName;

Password=myPassword;

Encrypt=true;

Trusted_Connection=false;

MultipleActiveResultSets=True" 

providerName="System.Data.SqlClient”

Related Links

Advertisements