EF-core with PostgreSQL migration error

asp.net-core asp.net-core-mvc entity-framework-core

Question

In my appsettings.json:

{
  "Data": {
    "DefaultConnection": {
      "ConnectionString": "Host=localhost;Username={{postgres}};Password={{postgres}};Database={{asp_trial_api}};Port=5432;Pooling=true;"
    }
},
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

And in my startup.cs:

 public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddDbContext<WebAPIDataContext>(options => {
                options.UseNpgsql(Configuration["Data:DefaultConnection:ConnectionString"]);
            });

            services.AddMvc();
            services.AddSwaggerGen();
        }

My dotnet ef migrations add initialwas successful however dotnet ef database updategives me following error:

28P01: password authentication failed for user "{{postgres}}"

The username and password I provided in my connection string is however correct. I have already created a blank database with the name asp_trial_api in my PostgresSQL.

What is going wrong here?

1
1
8/1/2018 5:35:19 AM

Popular Answer

The problem seems like have some missing attributes in the connection string such as User ID and Server. Try the following CS

"ConnectionStrings": {
    "DefaultConnection": "User ID=postgres;Password={{pass}};Server=localhost;Port=1234;Database={{database}};Integrated Security=true;Pooling=true;"
},

I have a GitHub Repo for a working example of an ASP.NET Core application with a Postgres database.

0
2/25/2017 9:37:46 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow