September 6, 2010

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.

I was working with ASP.NET classifieds starter kit.
When I Clicked on Post an Ad this is the error which i got


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.


[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.]
   System.Web.Util.SecUtility.CheckSchemaVersion(ProviderBase provider, SqlConnection connection, String[] features, String version, Int32& schemaVersionCheck) +1976968
   System.Web.Security.SqlMembershipProvider.CheckSchemaVersion(SqlConnection connection) +89
   System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +815
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
   System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78
   System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +60
   System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +119
   System.Web.UI.WebControls.Login.AttemptLogin() +115
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565





Solution :




In ASP.NET there is an API which allows Logins Membership maintained by ASPNETDB Database

Many of the Microsoft ASP.NET 2.0 providers are SQL providers—providers that persist state in SQL Server (or SQL Server Express) databases. The SQL providers include SqlMembershipProvider, SqlRoleProvider, SqlProfileProvider, SqlSessionStateStore, SqlWebEventProvider, and SqlPersonalizationProvider. Each stores data using a predefined schema.
 The Aspnet_regsql.exe tool that comes with ASP.NET 2.0 creates a SQL Server database with a compatible schema. 
That database, which is named aspnetdb by default, will hereafter be referred to as the SQL provider database or simply the provider database.

1.)Now First Check the databse reffered by SqlMemberShip Provider in Web.Config File.

in my case this is it
<membership>
   <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="classifiedsConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
   </providers>
  </membership>

Note : Make sure Some 
applicationName="Myclassified" is set in the above SqlMembershipProvider 

<connectionStrings>
  <add name="classifiedsConnection" connectionString="Data Source=LAKSH\SQLEXPRESS;Initial Catalog=ClassifiedStarterKit;Integrated Security=True;" providerName="System.Data.SqlClient"/>
 </connectionStrings>
 <appSettings>
2.) Now Second step is to Install the ASPNETDB in the referring DB by SQLMembershipProvider
    in my case it is reffering DB Specified by 
classifiedsConnection which is 

ClassifiedStarterKit

 To install the Tables , Scripts everything of ASPNETDB in 
ClassifiedStarterKit Db

Run the aspnet_regsql.exe from the below path by double clicking on it

C:\WINDOWS\microsoft.net\framework\v2.0.50727

3.) Follow the wizard steps give Your Server Name and select the DB (
ClassifiedStarterKit ) where your SqlMembershipProvider is pointing

4.)Above Step will install the Tables , Scripts, Procedures everything in your DB (
ClassifiedStarterKit )

5.)Now open the table aspnet_SchemaVersions
and check th entries 



common 1 True
membership 1 True
personalization 1 True
profile 1 True
role manager 1 True
Above data should be there if it is not Explicitly copy it in the table


Now it works!

3 comments:

  1. I always like your blog post because you always comes with different ideas and information. I always shared your site post with my friends. Keep posting and i will follow you.
    Web Security

    ReplyDelete
  2. Hello there,
    I m using Visual Studio 2010 SQL 2008 R2 .NET Framework 4.0 and i have use Aspnet_regsql.exe tool to import Membership and role tables into my current application database. Generate the Schema and run the Schema on my web hosting SQL.

    Add lines to config file:











    Now i m having the same error!

    Method Sys.Services.AuthenticationService.login has failed. 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.


    Please replay me how to fix this problem ... as i follow u r steps .. but didnt work for me.

    ReplyDelete
  3. Thankyou very much for the post...worked great.

    ReplyDelete