简体   繁体   中英

How to add pgadmin db in program.cs in asp.net mvc core

builder.Services.AddDbContext<DEM_MASTERSContext>(options => options.UseSQLserver(builder.Configuration.GetConnectionString("Database")));

how to add connection string for pgadmin 4, above one is for sqlserver

for postgres you can add like this

services.AddDbContext<PostgreSqlContext>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("Database")));

For more you can follow this or this

pgadmin4 is not a database, Do you want to ask how to connect to PostgreSQL?

First, you need to add NuGet package:

dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

Then, you need to add connectionstring in appsettings.json :

{
    "ConnectionStrings": {
        "WebApiDatabase": "Host=localhost; Database=xxx; Username=xxx; Password=xxx"
    },
}

Finally configure it like this:

services.AddDbContext<xxxContext>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("ConnectionStrings")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM