.Net Core Cant read connection string aus appsettings.json

Ich bin derzeit auf der Erstellung einer Web-Api .net core 2.0 und ich Sie einfach cant get my connection string zu arbeiten.

Habe ich meinen connectionstring in appsettings.json und laden Sie es in den Autostart.cs

Appsettings.json

{
"Logging": {
"IncludeScopes": false,
"Debug": {
  "LogLevel": {
    "Default": "Warning"
  }
},
"Console": {
  "LogLevel": {
    "Default": "Warning"
  }
},
"ConnectionStrings": {
  "DatabaseConnection": "Data Source=VMDEVSLN-EOE\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True"
  }
 }
}

Start.cs

        public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    //This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        var connection = Configuration.GetConnectionString("DatabaseConnection");
        services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(connection));
    }

    //This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseMvc();
    }
}

DbContext

public class DatabaseContext : DbContext
{
    public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
    {

    }
    public DbSet<CustomerTB> CustomerTB { get; set; }
}

Ich glaube das problem liegt irgendwo in meinem appsettings.json-aber ich kann nicht finden, dass es

  • Was, wenn Sie ändern Configuration.GetConnectionString("DatabaseConnection");zu Configuration["ConnectionStrings:DatabaseConnection"]
  • Immer noch der gleiche Fehler. Nicht lösen 🙁
  • Können Sie setzen einen Haltepunkt, wenn die Verbindungszeichenfolge ist entnommen aus appSettings?
  • Ich habe einen breakpunkt setzen. Es zeigt var connection = null
  • Setzen Sie einen Haltepunkt auf "Konfiguration" und überprüfen Sie, ob die Verbindungszeichenfolge ist in den Daten von einem der Anbieter
  • Versuchen Sie, sich zu bewegen appsettings.json zu sln-Verzeichnis

InformationsquelleAutor Ekos | 2017-08-24
Schreibe einen Kommentar