Home:ALL Converter>EF Core with Postgres connection string error

EF Core with Postgres connection string error

Ask Time:2017-02-25T05:49:06         Author:Thinker

Json Formatter

I am trying to use ASP.net Core along with postgres for the very first time. I was following (http://dotnetthoughts.net/using-postgresql-with-aspnet-core/) this blog post to create my first migration. I already created a database in my posgresSQL called asp_api_test.

My dotnet ef migrations add Initial was successful. However when I ran dotnet ef database update I ran into error Format of the initialization string does not conform to specification starting at index 0

My appsettings.json:

{
  "ConnectionStrings": {
    "DataAccessPostgreSqlProvider": "Host=localhost;Username=postgres;Password=root;Database=asp_trial_api;Pooling=true;"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

I am guessing my connection string is incorrect. My startup.cs:

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

            services.AddDbContext<WebAPIDataContext>(options => {
                options.UseNpgsql("DataAccessPostgreSqlProvider", b => b.MigrationsAssembly("New_Api"));
            });

            services.AddMvc();
        }

My project.json:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0",
    "Microsoft.ApplicationInsights.AspNetCore": "2.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

What am I doing wrong?

Author:Thinker,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42448882/ef-core-with-postgres-connection-string-error
yy