gpt4 book ai didi

c# - 条目(数据库)已添加

转载 作者:行者123 更新时间:2023-12-03 01:42:37 27 4
gpt4 key购买 nike

我有两个应用程序共享同一个数据库,即 APIMVC5 应用程序。两者都在本地主机上运行良好,但在部署到我的 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 });

}

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

更新

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

enter image description here

我还将初始目录添加到连接字符串中XLAB

最佳答案

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

关于c# - 条目(数据库)已添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51516204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com