因为直接卸载web.config里不太安全,所以想使用自己加密的连接串。
web.config里填写加密连接串
然后修改Context里base方法的参数,传入解密后的连接串
base里面
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;
}
大功告成!