Answer the question
In order to leave comments, you need to log in
How to set a password?
Can you please tell me how to set the password for the database in EF? Only not in the config, but from the c# code! In a sense, it will be entered in my textbox and transferred to EF.
Answer the question
In order to leave comments, you need to log in
There was such a problem at one time. I even left it for myself.
var originalConnectionString = ConfigurationManager.ConnectionStrings["коннекшенстрингнейм"].ConnectionString;
var entityBuilder = new EntityConnectionStringBuilder(originalConnectionString);
var factory = DbProviderFactories.GetFactory(entityBuilder.Provider);
var providerBuilder = factory.CreateConnectionStringBuilder();
providerBuilder.ConnectionString = entityBuilder.ProviderConnectionString;
providerBuilder.Add("Password", "Password123");
entityBuilder.ProviderConnectionString = providerBuilder.ToString();
using (var context = new YourContext(entityBuilder.ToString()))
{
// TODO
}
Pass the connection string with the required settings to the constructor of your DbContext.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question