/// <summary> /// 注册根据配置连接及指定驱动类型注册全局数据区厂对象,以便工厂直接创建数据库上下文 /// 连接字符串已加密 /// </summary> /// <param name="ConnectionStringKey">配置数据链接字符串健值,如果有多屋,则应如下:db:ConnStr</param> /// <param name="dbDriverType">指定驱动类型</param> /// <param name="Key">加密的密钥</param> /// <returns>返回应用注册对象,以便继续进行注册</returns> public IAppRegister RegGlobalDbContextForDecrypt(string ConnectionStringKey, DbDriverType dbDriverType, string Key = "") { string connstr = config.GetAppSetting(ConnectionStringKey).ToStringValue(); Global.DbContextFactory = DbContextFactory.CreateFactory(connstr, dbDriverType); return(this); }
//日志表必须包含以下几个字段:logid:主键ID(int 自动赠长),sysdomain:系统域名,ip:IP,logTime:日志时间,logcontent:日志详细内容 private static void logToTable(string ip, string domain, string logtype, DateTime logtime, string logcontent) { try { IDbContext db; if (SqlConnectStr.IsWhiteSpace()) { db = Global.DbContextFactory.CreateContext(); } else { db = DbContextFactory.CreateFactory(SqlConnectStr, DBType).CreateContext(); } //自动清空2年前日志 db.ExecuteCommand(System.Data.CommandType.Text, string.Format("delete from {0} where logtime<@logtime", logTable), db.Function.CreateParameter("@logtime", logtime.AddYears(-1))); //追加日志 db.ExecuteCommand(System.Data.CommandType.Text, string.Format("insert into {0} (sysdomain,ip,logtime,logtype,logcontent) values (@sysdomain,@ip,@logtime,@logtype,@logcontent)", logTable), db.Function.CreateParameter("@sysdomain", domain), db.Function.CreateParameter("@ip", ip), db.Function.CreateParameter("@logtime", logtime), db.Function.CreateParameter("@logtype", logtype), db.Function.CreateParameter("@logcontent", logcontent)); } catch { } }
/// <summary> /// 注册根据配置连接及指定驱动类型注册全局数据区厂对象,以便工厂直接创建数据库上下文 /// 连接字符串未加密 /// </summary> /// <param name="ConnectionStringKey">配置数据链接字符串健值,如果有多屋,则应如下:db:ConnStr</param> /// <param name="DbDriverTypeKey">指定驱动类型的配置键值</param> /// <returns>返回应用注册对象,以便继续进行注册</returns> public IAppRegister RegGlobalDbContext(string ConnectionStringKey, string DbDriverTypeKey) { string connstr = config.GetAppSetting(ConnectionStringKey).ToStringValue(); DbDriverType dbDriverType = (DbDriverType)config.GetAppSetting(DbDriverTypeKey).ToInt(); Global.DbContextFactory = DbContextFactory.CreateFactory(connstr, dbDriverType); return(this); }
/// <summary> /// 创建数据访问对象实例 /// </summary> /// <returns></returns> public static IDbContext CreateDbUtil(string ConnectionString, DbDriverType type) { return(DbContextFactory.CreateFactory(ConnectionString, type).CreateContext()); }