【问题标题】:Changing Identity's database更改身份的数据库
【发布时间】:2014-02-04 23:12:33
【问题描述】:

我正在尝试更改身份的数据库,更改 ApplicationDbContext:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("BOACopaEntities")
    {
    }
}

我把它从DefaultConnection 改成了BOACopaEntities...

我还将连接字符串添加到web.config

但是当我尝试运行我的应用程序时,我得到了错误:

Unable to load the specified metadata resource.

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.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.

Source Error: 


Line 200:
Line 201:            // Sign in the user with this external login provider if the user already has a login
Line 202:            var user = await UserManager.FindAsync(loginInfo.Login);
Line 203:            if (user != null)
Line 204:            {

有谁知道我还应该做些什么来解决这个错误?

这是 web.config:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561554e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Belintani.BOACopa.WebApplication-20131118010347.mdf;Initial Catalog=aspnet-Belintani.BOACopa.WebApplication-20131118010347;Integrated Security=True" providerName="System.Data.SqlClient" />-->
    <add name="BOACopaEntities" connectionString="metadata=res://*/BOACopaModel.csdl|res://*/BOACopaModel.ssdl|res://*/BOACopaModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxxxx;initial catalog=xxx;persist security info=True;user id=xxxx;password=xxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
         <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
       </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

【问题讨论】:

  • web.config 的相关部分是什么样的?
  • 什么是旧的连接字符串,什么是新的连接字符串。您使用的是代码优先还是模型优先?
  • 我先使用模型。我有一个具有 ADO.NET 模型的项目。我使用了与那里生成的相同的连接字符串!
  • 看起来数据库中没有您指向应用程序的身份表。
  • 我在数据库中创建了表!一定有别的东西!

标签: c# asp.net-mvc exception asp.net-mvc-5 asp.net-identity


【解决方案1】:

我设法让它工作......我玩了连接字符串。我认为这是因为提供程序类型不能是 Entity.Client,它必须是 Sql.Client……但无论如何……这是对我有用的 conn 字符串:

<add name="DefaultConnection" connectionString="Data Source=xxx;user id=xxx;password=xxx;Initial Catalog=xxx;Integrated Security=False" providerName="System.Data.SqlClient" />

【讨论】:

    【解决方案2】:

    我遇到了完全相同的问题。我创建了我的表并使用我的表和 asp.net 成员创建了实体框架模型。尝试使用相同的连接字符串,但我得到了同样的异常。在调查和使用它之后,我放弃并回滚到 DefaultConnection 使用。我认为这个问题的原因是在登录过程中使用的某些实体没有在模型中表示。

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多