/// <summary> 保存无效数据 /// 恢复事务性提交代码 hegf at 20101229 /// </summary> /// <param name="entityList"></param> public static void InsertUselessData(List<GPSDataEntity> entityList) { DbConnection dbConnection = null; string tableName = AppSetting.UselessDataTable; SQLCreator sqlCreator = new SQLCreator(); //将list中的数据写入数据库,每次写入IntMinExcuteCount条,直到将list中的数据全部写入为止 StringBuilder stringBuilder = null; try { //构造批量sql语句 stringBuilder = sqlCreator.BuildInsertUselessSQL(tableName, entityList); if (stringBuilder != null) { dbConnection = GetConnection(EnumDBOperationType.UselessDataDB); Logger.Info("InsertUselessData GetConnection执行完毕"); if (dbConnection == null) return; if (dbConnection.State != ConnectionState.Open) dbConnection.Open(); //事务注释掉是由于多线程调用引起IO争用。如果考虑负载则需要。 DbTransaction trans = dbConnection.BeginTransaction(); DbCommand cmd = dbConnection.CreateCommand(); cmd.Transaction = trans; cmd.CommandText = stringBuilder.ToString(); try { cmd.ExecuteNonQuery(); trans.Commit(); Logger.Info("InsertUselessData执行成功"); } catch (Exception ex) { trans.Rollback(); Loggers.LogInfo("PES.GPS.GPSStorage.GPSDataHelper.InsertUselessData:" + ex); } } } catch (Exception ex) { //Loggers.LogInfo("PES.GPS.GPSStorage.GPSDataHelper.InsertUselessData:" + stringBuilder); Loggers.LogInfo("PES.GPS.GPSStorage.GPSDataHelper.InsertUselessData:" + ex); } finally { stringBuilder = null; CloseDBConnection(dbConnection); } }
/// <summary> 保存无效数据 /// 恢复事务性提交代码 hegf at 20101229 /// </summary> /// <param name="entityList"></param> public void InsertUselessData(List<GPSDataEntity> entityList, string tableName) { DbConnection dbConnection = null; SQLCreator sqlCreator = new SQLCreator(); //将list中的数据写入数据库,每次写入IntMinExcuteCount条,直到将list中的数据全部写入为止 StringBuilder stringBuilder = null; try { using (dbConnection = GetConnection(EnumDBOperationType.UselessDataDB)) { //构造批量sql语句 stringBuilder = sqlCreator.BuildInsertUselessSQL(tableName, entityList); if (stringBuilder != null) { //事务注释掉是由于多线程调用引起IO争用。如果考虑负载则需要。 DbTransaction trans = dbConnection.BeginTransaction(); DbCommand cmd = dbConnection.CreateCommand(); cmd.Transaction = trans; cmd.CommandText = stringBuilder.ToString(); try { cmd.ExecuteNonQuery(); trans.Commit(); Logger.Info("InsertUselessData执行成功"); } catch (Exception ex) { trans.Rollback(); Logger.Warn("FetchData.InsertUselessData:" + ex); } } } } catch (Exception ex) { Logger.Warn("FetchData.InsertUselessData:" + ex); } }