在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
不多说,直接上代码 public partial class Model1 : DbContext { private static string connStr = ""; public Model1() : base("Data Source=.;Initial Catalog=GameDb;user id=sa;password=123456")//默认随便填一个标准连接字符串,如果不是标准的你的后面设置连接字符串会出错,具体原因大家有兴趣的去深究吧 {if (connStr == "") { connStr = ConfigurationManager.ConnectionStrings["Model1"].ConnectionString; connStr = SymmetricMethod.Decrypto(connStr); } base.Database.Connection.ConnectionString = connStr; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { } } web.config如下 <add name="Model1" connectionString="zgtsMV7VlXojlkp2VhEQvCsN6Pq/RsadZKfvOgqRWKPtBL8/x+2yBuSiWjfkMueEcAbFVTrI094JVLn28NnyiHlAqUl8q8g4T/ybEi4gPQPVEdUfg31xF8NLgWDCAGR9Tw+7/VTm/WRpBHxrpCwUwggB35QNgqkXo+1SQ6OmpqhrNdSuPrlzh1UoOHP/p55WrVL2TNOZ5n4v6CUmODdTVw==" providerName="System.Data.SqlClient" /> </connectionStrings> 其中 SymmetricMethod.Decrypto 解密算法,至于加解密算法,大家自行百度吧 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论