1
votes

I am using VS 2017 on a project with .NET Core 2.0 and PostgreSql database. Npgsql is used as a db provider.

This is how DbContext is configured:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
          options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"),
             b => b.MigrationsAssembly("MyAssembly")));

        ...
    }

This is the configuration of deployment Configuration When Web Deploy tries to apply migrations on publish process it gets an error:

Error : Web deployment task failed.

The value 'User ID=postgres;Host=localhost;Port=5432;Database=MyDatabase' is not a valid connection string or an absolute path. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_INVALID_CONNECTION_STRING.

Keyword not supported: 'host'. at System.Data.SqlClient.SqlConnectionStringBuilder.GetIndex(String keyword) at System.Data.SqlClient.SqlConnectionStringBuilder.set_Item(String keyword, Object value) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at System.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString) at Microsoft.Web.Deployment.ConnectionStringMatcher.RemoveExtraSlashFromDataSourceName(String connectionString) at Microsoft.Web.Deployment.ConnectionStringMatcher.GetStandardConnectionString(String userConnectionString, Boolean isSqlCE) at Microsoft.Web.Deployment.SqlInfo.GetBuilder(String connectionString, String errorMessageFormat) Publish failed to deploy.

Seems like Web Deploy tries to parse connection string via default SqlServer database provider. How can I switch the database provider to Npgsql for deployment?

1

1 Answers

0
votes

Do you use 'User ID=postgres;Host=localhost;Port=5432;Database=MyDatabase' as your connection string?

I think the problem is that you write 'User ID' which has a space in it, and you also don't include a password in the connection string.

Can you perhaps try this line instead, after you fill in the password?

"DefaultConnection": "Server=localhost;Port=5432;Database=MyDatabase;User=postgres;Password=YourPassword"