2

I would like to use the secure SqlCredential object to handle credentials for connecting to our SQL database.

.NET has an overload of the SqlConnection constructor that takes a connection string and SqlCredential so you don't have to embed the credentials in the connection string itself. I would like to use something similar for Entity Framework when creating a DBContext instance.

  1. I need to control the connection string that gets used by Entity Framework for the connection.
  2. I would like to use the more secure way of handling credentials, using either SQLCredential, NetworkCredential, or SecureString and passing that to the DBContext to create the connection.

Is there any way to do this?

(As an aside, we can't use Windows integrated security as our database is not set up for that and I am not in a position to change that.)

1

1 Answer 1

4

You can create a regular SqlConnection with SqlCredential like you're used to and then pass this to the constructor of the entity framework DbContext.

The DbContext has this constructor:

public DbContext(DbConnection existingConnection, bool contextOwnsConnection);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.