D
D
DarkByte20152016-05-10 22:57:41
C++ / C#
DarkByte2015, 2016-05-10 22:57:41

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

2 answer(s)
A
Anton Agaltsov, 2016-05-10
@Archusha

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
}

Sorry if it doesn't work. I don’t know for sure whether I pulled it out of the working code. But I think the direction for Google gave)

F
Fat Lorrie, 2016-05-11
@Free_ze

Pass the connection string with the required settings to the constructor of your DbContext.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question