private System.Threading.ReaderWriterLock rwl; public DataBase() { rwl = new System.Threading.ReaderWriterLock(); } /// <summary> /// 该方法Command执行ExecuteReader操作 /// </summary> public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null) { rwl.AcquireWriterLock(System.Threading.Timeout.Infinite); IDataReader drReader; SqlConnection(sqlText, false); AddParameter(parameterList); IDBConnection.Open(); drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection); rwl.ReleaseWriterLock(); return drReader; }
private static object objLock = new object(); /// <summary> /// 该方法Command执行ExecuteReader操作 /// </summary> public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null) { lock (objLock) { IDataReader drReader; SqlConnection(sqlText, false); AddParameter(parameterList); IDBConnection.Open(); drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection); return drReader; } }
static int i = 0; /// <summary> /// 该方法Command执行ExecuteReader操作 /// </summary> public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null) { IDataReader drReader = null; while (true) { if (i == 0) { System.Threading.Interlocked.Increment(ref i); SqlConnection(sqlText, false); AddParameter(parameterList); IDBConnection.Open(); drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection); System.Threading.Interlocked.Decrement(ref i); break; } } return drReader; }