I am trying to connect to sql db using username and password. I have saved the password in the windows environment and named it "HSPA_DBPassword" and here is what i have:
appsettings.json
"ConnectionStrings": {
"Default": "server=rwahdan; database=hspa; User Id=sa;"
},
program.cs:
var builder2 = new SqlConnectionStringBuilder(
builder.Configuration.GetConnectionString("Default"));
builder2.Password = builder.Configuration.GetSection("DBPassword").Value;
var ConnectionString = builder2.ConnectionString;
builder.Services.AddDbContext<DataContext>(options =>
options.UseSqlServer(ConnectionString, option =>
{
option.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
})
);
there is mistake that I have builder and builder2 and in my cs file i have builder set to handle the configuration and I am not sure why is that? I don't have a startup file as well.
with my code I am getting error that the password is null but it is saved in windoes invironemt and the appsettings.json i removed the password.
error:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'Password')