【问题标题】:The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'“System.Web.Security.SqlMembershipProvider”需要与架构版本“1”兼容的数据库架构
【发布时间】:2011-03-18 14:14:17
【问题描述】:

我有一个 SQL Server 2008 数据库,其中包含许多填充数据的表,我使用 SQL Server Management Studio 通过使用脚本向导生成 SQL 转储:任务 -> 生成脚本 -> 为所选数据库中的所有对象编写脚本,以及选择脚本数据选项。我确保将“服务器版本脚本”的值更改为“SQL Server 2008”。然后我创建了一个新数据库并在新数据库上运行 SQL 转储以生成旧数据库的相同副本。然后我将权限分配给我的默认用户到新数据库。然后我更改了 ASP.NET 应用程序上的连接字符串以使用新数据库。但是当我运行它时,它会引发以下异常 -

            Server Error in '/myapp' Application.
            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.
            Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            Exception Details: 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.

            Source Error:

            An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

            Stack Trace:

            [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) +1977772
               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

【问题讨论】:

    标签: asp.net sql


    【解决方案1】:

    旧帖子,但我有一个替代解决方案。

    我在web.config 中的连接字符串包括Persist Security Info=True;。删除它解决了错误。

    【讨论】:

      【解决方案2】:

      我尝试了上述许多选项,但当时似乎都没有解决问题(尽管它们可能有所帮助,但我没有意识到)。

      我采取的最后一步 [有效] 是授予我连接字符串中的 SQL 用户访问由 aspnet_regsql.exe 安装的 aspnet_* 角色的权限。我的 SQL 用户被设置为数据库的 db_owner,但不是系统管理员 - 不确定这是否重要。

      只要我这样做了,之后我已经尝试了上面的一些选项,一切都很好。

      【讨论】:

      • 欢迎来到 Stack Overflow!请format您的答案以提高其可读性。
      【解决方案3】:

      我有一个类似的问题,我能够解决它添加默认值到表 aspnet_SchemaVersions。 此默认值未添加到使用 Tasks -> Generate Scripts 生成的数据库中。

      这里有一个有用的post

      INSERT INTO dbo.aspnet_SchemaVersions 
      VALUES
      ('common', 1, 1),
      ('membership', 1, 1),
      ('role manager', 1, 1);
      GO
      

      【讨论】:

      • 我也遇到过在任务 -> 生成脚本后这些值丢失的情况。每个人都应该检查他们在 aspnet_Schemaversions 中是否有任何值,然后再采用更复杂的方法来解决此问题
      【解决方案4】:

      我找到了一个很简单的方法,把这些数据粘贴到aspnet_SchemaVersions表中

      common              1   True
      health monitoring   1   True
      membership          1   True
      personalization     1   True
      profile             1   True
      role manager        1   True
      

      我不得不使用几个空格来使数据对齐,忽略空格

      【讨论】:

      • 怎么回事...谢谢,亚历克斯。这对我有用。好随便喔。如此晦涩。
      • 有了这个解决方案就不用重新编译了,重启站点就搞定了
      • @arunendra 也是我的问题。谢谢。
      • 当我认为我可以删除并重新创建 asp 表以“清除”新应用程序的所有用户、角色等时,这只是解决了我的问题。
      • 就我而言,我还需要重新启动应用程序池。
      【解决方案5】:

      尝试使用正确版本的 System.Web.Security.SqlRoleProvider 更新 Web 配置文件

      您可以在 c:/windows/microsoft.net/framework/v4.0.30319 或任何其他版本中找到以下配置,在那里您可以找到配置文件。在其中检查机器配置文件 获取版本和公钥。

      对于 .net 框架 4.0

           <roleManager enabled="true" defaultProvider="SqlProvider">
           <providers>
              <clear/>
              <add name="SqlProvider" connectionStringName="rolesDB" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
           </providers>
        </roleManager>
      

      适用于 .net 框架 2.0

          <roleManager enabled="true" defaultProvider="SqlProvider">
           <providers>
              <clear/>
              <add name="SqlProvider" connectionStringName="rolesDB" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
           </providers>
        </roleManager>
      

      【讨论】:

        【解决方案6】:

        这基本上是在您复制/过去完整的网站解决方案时出现的。 SQL 服务器的 ASP.NET 配置应单独配置。这意味着您应该从 Visual Studio 命令提示符运行 aspnet_regsql 并在向导期间相应地按照说明进行操作。

        【讨论】:

          【解决方案7】:

          我忘记在我的新数据库上运行 aspreg_sql 后第一次收到此错误。完成后,我收到此错误,直到我关闭 Cassini 或 ASP.NET 开发服务器。重新运行,它工作正常。

          【讨论】:

            【解决方案8】:

            就我而言,上述解决方案均无效。

            我从由visual studio创建的webconfig中的memnership provider中删除了applicationName="/",然后将其上传到服务器。

            或者您可以手动在 aspnet_Applications 表中创建应用程序行。

            祝你编码愉快!

            【讨论】:

              【解决方案9】:

              您可能必须运行 aspnet_regsql.exe 才能填充您的架构值。只要您拥有所有生成的对象(表、视图、sproc 等),您就可以对这些值进行硬编码。

              我为解决这个问题而采取的步骤是:

              重新运行 aspnet_regsql.exe 确保有默认值 重新启动 IIS。

              然后它起作用了..

              但是,如果您只是复制没有值的数据库架构,则需要运行“aspnet_regsql.exe”来填充默认值。

              文件可以在这里找到(re: msdn): [驱动器:]\%windir%\Microsoft.NET\Framework\version(在 2.0 目录中)

              这里有一些信息:
              http://msdn.microsoft.com/en-us/library/ms229862%28v=vs.80%29.aspx

              【讨论】:

              • 我认为这可能是官方的方式,所以我就这样做了,它工作得很好。
              【解决方案10】:

              我根本不是 SQL 或 ASP.net 大师或程序员,偶然得到这份工作,但我遇到了同样的问题,而且错误很愚蠢:

              在我的Web.Conf 中,连接字符串通常看起来像这样:

              <add name="AgriConnectionString" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=AgriBranch; pooling=true; Connection Timeout=120; Integrated Security=false;Persist Security Info=True; User ID=UserID; Password=PASS***WORD" providerName="System.Data.SqlClient" />
              

              然而昨天我不小心让我的来源看起来像这样"Data Source=./SQLEXPRESS"

              我得到了与讨论相同的错误。

              这个错误也解释了为什么使用 Visual Studio 的实用程序使站点脱机并重新联机或重新编译时会修复错误。

              【讨论】:

                【解决方案11】:

                重新启动应用程序池对我有用

                【讨论】:

                • 对我来说,它混淆了我的内心深处。
                • 这应该有更多的支持 - 尽管其他解决方案解决了缺少数据的情况,但如果它存在并且您的表格看起来一切正常,那么将其关闭然后再次打开对我来说是诀窍
                【解决方案12】:

                如果你真的没有忘记任何东西(视图、SP 等等等等),那么谷歌搜索表明“愚蠢”的解决方案,比如关闭项目并重新打开、重建,或者:

                真正做到这一点的是通过 ASP.NET 配置实用程序(Visual Studio - 在网站菜单下),使应用程序脱机然后重新联机。这实际上只是对 web.config 进行了更改(不完全确定更改是什么)。因此,在将其离线后,我不得不将 web.config 上传到托管解决方案。然后将应用程序重新上线,重新复制 web.config 等。

                可能是答案。

                【讨论】:

                • 谢谢,为我节省了大量时间。
                • 再次为我工作。完成此操作后,我将我的应用程序发布到服务器并且它正在工作!
                • 这太奇怪了——为什么让它再次离线/在线工作?发生了什么变化? TFS 说我的 Web.config 没有任何变化。也许在数据库中进行了更改?
                • 是的 - 正如您所说,关键似乎是对 web.config 的更改。我只是打开了我的 web.config,添加了一个空格,删除了那个空格并点击了保存。立即开始工作。感谢您的详尽回答!
                • 脱机然后重新联机对我来说效果很好:)
                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-07-23
                相关资源
                最近更新 更多