简体   繁体   English

如何在 asp.net mvc 核心的 program.cs 中添加 pgadmin db

[英]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的

for postgres you can add like this对于 postgres,您可以像这样添加

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? 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.

相关问题 如何返回在 Program.cs ASP.Net core 6 中找不到 - How to return not found in Program.cs ASP.Net core 6 ASP.NET Core 6 MVC:如何从 controller 访问 Program.cs 中定义的变量值? - ASP.NET Core 6 MVC : how to access a variable's value that is defined in Program.cs from a controller? ASP.NET 核心 Web API - 如何将 .NET 核心 5 中的 SetupSerilog 转换为 .NET 核心 6 Program.cs - ASP.NET Core Web API - How to convert SetupSerilog in .NET Core 5 to .NET Core 6 Program.cs ASP.NET 核心程序.cs配置 - ASP.NET Core program.cs configuration 避免在ASP.NET Core Program.cs中使用静态值 - Avoid static value in ASP.NET Core Program.cs ASP.NET Core MVC 中 Program.cs 中的 System.AggregateException - System.AggregateException in Program.cs in ASP.NET Core MVC Asp.Net Core 3 如何在 program.cs 文件中放入 function - 修饰符“private”对此项目无效 - Asp.Net Core 3 how to put a function in the program.cs file - The modifier 'private' is not valid for this item Asp.net core 6 Program.cs文件中appsettings.json的使用方法 - How to use appsettings.json in Asp.net core 6 Program.cs file 如何从 program.cs 中的 appsettings 中读取 UrlPrefixes - asp.net core 3.1 - how to read UrlPrefixes from appsettings in program.cs - asp.net core 3.1 如何从 ASP.NET Core 中的 Program.cs 访问 IWebHostEnvironment - How to access IWebHostEnvironment from Program.cs in ASP.NET Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM