ef 数据库连接字符串加密

时间:2023-03-08 18:10:20
public testContext()
: base(GetConnection(), true)
{ }
public static DbConnection GetConnection()
{
var providerName = ConfigurationManager.ConnectionStrings["testContext"].ProviderName;
var conn = DbProviderFactories.GetFactory(providerName).CreateConnection();
var connectString = ConfigurationManager.ConnectionStrings["testContext"].ConnectionString;
conn.ConnectionString = connectString.Decrypt();//解密
return conn;
}