[英]Can I use SqlCredential with Entity Framework for the SQL connection?
I would like to use the secure SqlCredential object to handle credentials for connecting to our SQL database. 我想使用安全的SqlCredential对象来处理用于连接到我们的SQL数据库的凭据。
.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. .NET具有SqlConnection构造函数的重载,该构造函数采用连接字符串和SqlCredential,因此您不必在连接字符串本身中嵌入凭据。 I would like to use something similar for Entity Framework when creating a DBContext instance. 创建DBContext实例时,我想对Entity Framework使用类似的东西。
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.) (顺便说一句,我们不能使用Windows集成安全性,因为我们没有为此设置数据库,而且我无权更改它。)
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. 您可以像以前一样使用SqlCredential创建常规SqlConnection,然后将其传递给实体框架DbContext的构造函数。
The DbContext has this constructor: DbContext具有以下构造函数:
public DbContext(DbConnection existingConnection, bool contextOwnsConnection);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.