В файле appsettings.json:
Код: Выделить всё
{
"ConnectionStrings": {
"MPmain": "Data Source=DESKTOP-FCT8VC2;Initial Catalog=mpau;Integrated Security=True;TrustServerCertificate=true",
"MPpostgres1": "User ID=postgres;Password=xxxxxxxx;Server=localhost;Port=5432;Database=mpau;",
"MPpostgres": "host=localhost port=5432 dbname=mpau user=postgres password=xxxxxxxx connect_timeout=10 sslmode=prefer"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Код: Выделить всё
using Microsoft.EntityFrameworkCore;
using Npgsql;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
//added
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(
policy =>
{
policy.AllowAnyOrigin();
policy.AllowAnyMethod();
policy.AllowAnyHeader();
});
});
//added
builder.Services.AddDbContext(options =>
{
builder.Configuration.GetConnectionString("postgres");
options.UseNpgsql("postgres");
});
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Код: Выделить всё
"Format of the initialization string does not conform to specification at index 0"
Большинство результатов поиска утверждают, что это, скорее всего, вызвано ошибкой в строке подключения, но я пробовал несколько изменений, и Я следовал руководству, в котором использованная строка была почти идентична (за исключением имени пользователя и пароля, и позже я попробую аутентификацию Kerberos, чтобы удалить ее из строки подключения).
Любая помощь в устранении этой ошибки мы будем очень признательны.
Подробнее здесь: https://stackoverflow.com/questions/786 ... postgresql
Мобильная версия