打赏

ef 数据库连接字符串加密

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;
        }

 

posted @ 2018-06-29 14:47  Bear.Tirisfal  阅读(1344)  评论(0编辑  收藏  举报