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