繁体   English   中英

条目(数据库)已经添加

[英]The entry (Database) has already been added

我有两个共享相同数据库的应用程序,它们是一个API和一个MVC5应用程序。 两者都可以在localhost上很好地运行,但是在部署到我的Azure帐户时却遇到此错误

 Configuration Error

Description: An error occurred during the processing of a configuration
             file required to service this request. Please review the
             specific error details below and modify your configuration file appropriately.

Parser Error Message: The entry 'XlabDatabase' has already been added.

Source Error:

 An application error occurred on the server. The current custom error settings
 for this application prevent the details of the application error from being viewed remotely (for security reasons)

我已经采取措施甚至重命名数据库,但是在部署时我使用相同的远程字符串

这是我的MVC应用程序连接字符串

<connectionStrings>
   <add name="XlabDatabase_acc" providerName="System.Data.SQLClient" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;MultipleActiveResultSets=true;App=EntityFramework" />
</connectionStrings>

这是我的MVC上下文

    public virtual DbSet<Account> Accounts { get; set; }
    public virtual DbSet<AnnualReport> AnnualReports { get; set; }
    public virtual DbSet<MonthlyReport> MonthlyReports { get; set; }
    public virtual DbSet<WeekReport> WeekReports { get; set; }

    protected override void OnModelCreating(DbModelBuilder builder)
    {
        base.OnModelCreating(builder);
        builder.Entity<AnnualReport>().HasKey<int>(x => x.AnnualReportID);
        builder.Entity<MonthlyReport>().HasKey<int>(x => x.MonthlyReportID);
        builder.Entity<WeekReport>().HasKey<int>(x => x.ReportID);

    }

这是我的API连接字符串

  <connectionStrings>
     <add name="XlabDatabase" providerName="System.Data.SQLClient" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;MultipleActiveResultSets=true;" />
  </connectionStrings>

这是我的API上下文

 public virtual DbSet<Customers> Customers { get; set; }
    public virtual DbSet<Salesman> Salesman { get; set; }
    public virtual DbSet<Route> Route { get; set; }
    public virtual DbSet<Purchase> Purchase { get; set; }
    public virtual DbSet<Products> Products { get; set; }
    public virtual DbSet<Assets> Assets { get; set; }
    public virtual DbSet<WeekReports> WKReports { get; set; }
    public virtual DbSet<MonthlyReports> MONReports { get; set; }
    public virtual DbSet<AnnualReports> ANNReports { get; set; }
    public virtual DbSet<Accounts> Accounts { get; set; }
    public virtual DbSet<LoadingOrder> LoadingOrder { get; set; }


    protected override void OnModelCreating(DbModelBuilder builder)
    {

        base.OnModelCreating(builder);

        builder.Conventions.Remove<PluralizingTableNameConvention>();
        builder.Entity<LoadingOrder>().HasRequired(c => c.Salesman).WithMany().WillCascadeOnDelete(false);
        builder.Entity<IdentityUserClaim>().ToTable("UserClaim").HasKey<Int32>(r => r.Id);
        builder.Entity<IdentityUserLogin>().ToTable("UserLogin").HasKey<string>(l => l.UserId);
        builder.Entity<IdentityRole>().ToTable("Role").HasKey<string>(r => r.Id);
        builder.Entity<User>().ToTable("User").HasKey(r => new{ r.IDNumber, r.UserName});
        builder.Entity<IdentityUser>().ToTable("User").HasKey<string>(r => r.UserName);
        builder.Entity<IdentityUserRole>().ToTable("UserRole").HasKey(r => new { r.RoleId, r.UserId });

    }

我已将两个应用程序部署到两个不同的虚拟应用程序和目录中。

UPDATE

这就是我部署共享相同连接字符串的两个应用程序的方式

在此处输入图片说明

我还将Initial Catalog添加到了连接字符串XLAB

在连接字符串上,在<providers>和第一个<add....>节点之前,添加一个<clear />节点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM