예제 #1
0
        /// <summary>
        /// 并发操作检测
        /// </summary>
        /// <returns></returns>
        //private bool CheckIsConcurrent()
        //{
        //    int waitTimes = 500;//5秒
        //    while (_dbOperator.ContainsKey(DataBase) && _dbOperator[DataBase] && waitTimes > -1)
        //    {
        //        waitTimes--;
        //        System.Threading.Thread.Sleep(10);
        //        if (waitTimes == 0)
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}
        private DbDataReader ExeDataReaderSQL(string cmdText, bool isProc)
        {
            DbDataReader sdr     = null;
            ConnBean     coSlave = null;

            if (!isOpenTrans)// && _IsAllowRecordSql
            {
                coSlave = connObject.GetSlave();
            }
            else if (useConnBean.IsSlave)// && 事务操作时,如果在从库,切回主库
            {
                ResetConn(connObject.Master);
            }
            if (OpenCon(coSlave, AllowConnLevel.MaterBackupSlave))
            {
                try
                {
                    CommandBehavior cb = CommandBehavior.CloseConnection;
                    if (_IsAllowRecordSql)//外部SQL,带表结构返回
                    {
                        cb = isOpenTrans ? CommandBehavior.KeyInfo : CommandBehavior.CloseConnection | CommandBehavior.KeyInfo;
                    }
                    else if (isOpenTrans)
                    {
                        cb = CommandBehavior.Default;//避免事务时第一次拿表结构链接被关闭。
                    }
                    sdr = _com.ExecuteReader(cb);
                    if (sdr != null)
                    {
                        recordsAffected = sdr.RecordsAffected;
                    }
                }
                catch (DbException err)
                {
                    string msg = "ExeDataReader():" + err.Message;
                    debugInfo.Append(msg + AppConst.BR);
                    recordsAffected = -2;
                    WriteError(msg + (isProc ? "" : AppConst.BR + GetParaInfo(cmdText)));
                }
                //finally
                //{
                //    if (coSlave != null)
                //    {
                //        ChangeConn(connObject.Master);//恢复链接。
                //    }
                //}
            }
            return(sdr);
        }
예제 #2
0
파일: DbBase.cs 프로젝트: ithanshui/cyqdata
        /// <summary>
        /// 并发操作检测
        /// </summary>
        /// <returns></returns>
        //private bool CheckIsConcurrent()
        //{
        //    int waitTimes = 500;//5秒
        //    while (_dbOperator.ContainsKey(DataBase) && _dbOperator[DataBase] && waitTimes > -1)
        //    {
        //        waitTimes--;
        //        System.Threading.Thread.Sleep(10);
        //        if (waitTimes == 0)
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}
        private DbDataReader ExeDataReaderSQL(string cmdText, bool isProc)
        {
            DbDataReader sdr     = null;
            ConnBean     coSlave = null;

            if (!isOpenTrans && _IsAllowRecordSql)
            {
                coSlave = connObject.GetSlave();
            }
            if (OpenCon(coSlave))
            {
                try
                {
                    sdr = _com.ExecuteReader(isOpenTrans ? CommandBehavior.KeyInfo : CommandBehavior.CloseConnection | CommandBehavior.KeyInfo);
                    if (sdr != null)
                    {
                        recordsAffected = sdr.RecordsAffected;
                    }
                }
                catch (DbException err)
                {
                    string msg = "ExeDataReader():" + err.Message;
                    debugInfo.Append(msg + AppConst.BR);
                    recordsAffected = -2;
                    WriteError(msg + (isProc ? "" : AppConst.BR + GetParaInfo(cmdText)));
                }
                //finally
                //{
                //    if (coSlave != null)
                //    {
                //        ChangeConn(connObject.Master);//恢复链接。
                //    }
                //}
            }
            return(sdr);
        }