Tuesday 26 October 2010

SqlMembershipProvider requires a database schema compatible with schema version 1

Whilst recently working with the ASP.Net Membership tools, I decided to script a copy of an existing database with the same Schema. This, I thought, would save a bit of time and get me working quickly. Unfortunately my application experienced the following error when calling the Membership.ValidateUser() method:

System.Configuration.Provider.ProviderException: The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'. However, the current database schema is not compatible with this version. You may need to either install a compatible schema with aspnet_regsql.exe (available in the framework installation directory), or upgrade the provider to a newer version.

After a bit of research, I found the following blog post Schema Changes in the latest ASP.NET V2.0 bits which seemed to fit with what I was doing. Unfortunately running the aspnet_regsql.exe tool with the option to "Configure SQL Server for application services" didn't fix it for me.

After reading this forum post I looked (quite rightly) into the aspnet_SchemaVersions table. Sure enough the data was empty so I ran the tool trying various configurations detailed on the msdn page.

Using the visual studio command prompt, I ran the following command. This sets up the membership, role provider, and profile tables on a database called My_Membership located at localhost using integrated credentials:


aspnet_regsql.exe -E -S localhost -A mrp -d My_Membership

This successfully populated the data as expected. Unfortunately this didn't resolve my issue, I was still getting the exact same error!

After taking a step back and assessing what I had changed, I realised that the only actual difference was the application name (specified in the web config). With this in mind I was able to check through the database and noticed that there was an aspnet_Applications table with the old application name in (but not my new version). After adding in my new application name it all worked fine... Phew!

Typically, once I solved it I stumbled across this scott gu blog entry Always set the "applicationName" property when configuring ASP.NET 2.0 Membership and other Providers which goes through pretty much the same issue. If only I had seen that first.

In summary. If you get this error, check that the application name matches an entry in the aspnet_Applications table. Or better still, run through the proper setup steps...

No comments:

Post a Comment