Schema compatiblity error in configuring SqlMembershipProvider
I was working with one of my projects in which I had to use Membership/Role providers. I run the wizard using aspnet_regsql.exe to create the structure of SqlMembershipProvider. I added few roles and users using ASP.Net Configuration. Everything worked fine tested my application multiple times and it worked very well. Then I generated the script from my local database for SqlMembershipProvider since we can not run the utility aspnet_regsql.exe on our test server. Everything went well so far. All the tables, views, stored procedures, roles were created and permissions were granted. Then when I try to run my application from the test server it gave me following error.
"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."
This was a bit confusing error for me since I had worked with SqlMembershipProvider in the past. Then I start recalling the difference between my previous and current deployment and the difference was in ealier deployments either I used aspnet_regsql.exe or copied the structure with data but this time I created the script and generate the structure.
Still no sign for me to detect the cause of error. Then I started checking the tables and I found that when we run aspnet_regsql.exe it not only creates the structure but insert some values as well in "aspnet_SchemaVersions" table which were missing in my test server. So created manual insert script to add following values.
-- --Table: [dbo].[aspnet_SchemaVersions]
-- --Insert
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'common', N'1', 1)
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'health monitoring', N'1', 1)
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'membership', N'1', 1)
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'personalization', N'1', 1)
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'profile', N'1', 1)
INSERT INTO [dbo].[aspnet_SchemaVersions] ([Feature], [CompatibleSchemaVersion], [IsCurrentVersion]) VALUES(N'role manager', N'1', 1)
BINGO!!! After inserting these values my test server started working as good as my local machine :).