I have a .net core 6.0 web api project. I am using entity framework code first. I am trying to login with sa user. I set a password for sa user on sql server management and I am able to login with sa user and password on sql server managment. But I set the same username(sa) and password I am not able to login. So the database is not create. I have received a login failed message.
my appsettings.json
{"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning"}},"AllowedHosts": "*","ConnectionStrings": {"DefaultConnection": "Data Source=localhost;Database=userdddd;Persist Security Info=True;User Id=SA;Password=YXZakamoz21?-*54;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True;Connection Timeout=10;"}}
My userDbcontex
namespace ffff.Userwebservice.DbContex{public class UserDbContext : DbContext{public UserDbContext(DbContextOptions<UserDbContext> options) : base(options){}
DbSet<Users> Users { get; set; }
DbSet<AccessGrants> AccessGrants { get; set; }
}
}
My program.cs
using ffff.Userwebservice.Repository;using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
builder.Services.AddDbContext<UserDbContext>(options =>options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"), sqlOptions =>{sqlOptions.EnableRetryOnFailure(maxRetryCount: 5,maxRetryDelay: TimeSpan.FromSeconds(3),errorNumbersToAdd: null);}).EnableSensitiveDataLogging());
var app = builder.Build();
// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment())if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}
app.UseHttpsRedirection();
//app.UseAuthorization();
app.MapControllers();
app.Run();
I tryed many type of the connection. But I could not logined with entity framework. enter image description here