I'm getting this error:

Entity Framework Core 6.0.25 initialized 'GerenciadorContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.25' with options: None

fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database 'GerenciadorDeProjetos' on server 'DESKTOP-707QCVQ'.
fail: Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of a query for context type 'GerenciadorDeProjetos.Data.GerenciadorContext'.

My program.cs:

var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("Default");
var myAllowSpecificOrigins = "_var myAllowSpecificOrigins";

builder.Services.AddDbContext<GerenciadorContext>(opts =>
{
  opts.UseSqlServer(connectionString);
});

builder.Services.AddCors(opts =>
{
    opts.AddPolicy(name: myAllowSpecificOrigins, builder =>
    {
        builder.WithOrigins("http://127.0.0.1:5500")
        .AllowAnyOrigin()
        .AllowAnyHeader();
    });
});

builder.Services.AddIdentity<Usuario, IdentityRole>()
    .AddEntityFrameworkStores<GerenciadorContext>()
    .AddDefaultTokenProviders();


builder.Services.AddTransient<IUserDao, UserDao>();


builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseCors(myAllowSpecificOrigins);

app.UseAuthorization();

app.MapControllers();

app.Run();

My connection string:

"Data Source=DESKTOP-707QCVQ;Initial Catalog=GerenciadorDeProjetos;Integrated Security=True;Trust Server Certificate=True"
0

There are 0 best solutions below