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
- The Windows Azure Platform Training Kit has been updated. You can download it here.
- Attend a FREE Windows Azure Discovery Workshop in the UK
I Eric what do i need to change to enable Universal Providers Session State Provider in addition to configure the right connection string in web config and adding the Reference to System.Web.Providers?
Do i need to prepare my SQL Azure Database with a script to create the appropriate tables?
I’ve already setup my environment to work with Universal Providers. Unfortunately i’m still facing a problem the Session State only works for me when i publish the web application in windows azure. When i use the SQL Azure connection string locally in Compute Emulator or when i use a Connection String that points out to my SQL Server 2008 R2 installation the Session State is not maintained?! I wonder what might be wrong….