[英]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"))); 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如何为pgadmin 4添加连接字符串,上面一个是用于sqlserver的
pgadmin4
is not a database, Do you want to ask how to connect to PostgreSQL? pgadmin4
不是数据库,请问如何连接PostgreSQL?
First, you need to add NuGet package:首先,您需要添加 NuGet package:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
Then, you need to add connectionstring
in appsettings.json
:然后,您需要在
appsettings.json
中添加connectionstring
字符串:
{
"ConnectionStrings": {
"WebApiDatabase": "Host=localhost; Database=xxx; Username=xxx; Password=xxx"
},
}
Finally configure it like this:最后配置如下:
services.AddDbContext<xxxContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("ConnectionStrings")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.