コード例 #1
0
ファイル: GpsDataHelper.cs プロジェクト: hhahh2011/CH.Gps
        /// <summary> 保存补传数据
        /// 恢复事务性提交代码  hegf at 20101229
        /// </summary>
        public static void InsertFetchData(List<GPSDataEntity> entityList)
        {
            DbConnection dbConnection = null;
            string tableName = "gps_fetchdata";
            SQLCreator sqlCreator = new SQLCreator();
            StringBuilder stringBuilder = null;
            try
            {
                stringBuilder = sqlCreator.BuildInsertFetchSQL(tableName, entityList);
                if (stringBuilder != null)
                {
                    dbConnection = GetConnection(EnumDBOperationType.FetchDataDB);
                    Logger.Info("InsertFetchData 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("InsertFetchData 执行成功");
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        Logger.Warn("保存补传数据错误 PES.GPS.GPSStorage.GPSDataHelper.InsertFetchData:" + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("PES.GPS.GPSStorage.GPSDataHelper.InsertFetchData:" + ex);
            }
            finally
            {
                stringBuilder = null;
                CloseDBConnection(dbConnection);
            }
        }
コード例 #2
0
ファイル: FetchData.cs プロジェクト: hhahh2011/CH.Gps
        /// <summary> 保存补传数据
        /// 恢复事务性提交代码  hegf at 20101229
        /// </summary>
        public void InsertFetchData(List<GPSDataEntity> entityList)
        {
            DbConnection dbConnection = null;
            string tableName = "gps_fetchdata";
            SQLCreator sqlCreator = new SQLCreator();
            StringBuilder stringBuilder = null;
            try
            {
                using (dbConnection = GetConnection(EnumDBOperationType.FetchDataDB))
                {
                    stringBuilder = sqlCreator.BuildInsertFetchSQL(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("InsertFetchData 执行成功");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Logger.Warn("保存补传数据错误 FetchData.InsertFetchData:" + ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("FetchData.InsertFetchData:" + ex);
            }
        }