private void ValidateConnectionAndTransaction(string method) { if (null == _connection) { throw ADP.ConnectionRequired(method); } _transaction = _connection.SetStateExecuting(method, Transaction); _cmdState = ConnectionState.Executing; }
private void ValidateConnectionAndTransaction(string method) { if (this._connection == null) { throw ADP.ConnectionRequired(method); } this._transaction = this._connection.SetStateExecuting(method, this.Transaction); this.cmdState = ConnectionState.Executing; }
protected DataBaseODBCConnection() { connectionConfig = new Encrypter().DecryptText( ConfigurationManager.ConnectionStrings["RopSqlConnStr"].ConnectionString); cultureAcronym = ConfigurationManager.AppSettings["RopSqlCulture"]; connection = new OdbcConnection(connectionConfig); transactionControl = null; }
internal void CloseFromConnection() { if (this._parameterCollection != null) { this._parameterCollection.RebindCollection = true; } this.DisposeDataReader(); this.CloseCommandWrapper(); this._isPrepared = false; this._transaction = null; }
internal void CloseFromConnection() { if (null != _parameterCollection) { _parameterCollection.RebindCollection = true; } DisposeDataReader(); CloseCommandWrapper(); _isPrepared = false; _transaction = null; }
internal void CloseFromConnection() { DisposeDataReader(); if (_cmdWrapper != null) { _cmdWrapper.Dispose(true); } _isPrepared = false; _hdesc = IntPtr.Zero; this.transaction = null; }
private static int GetTablesCount(string tableName, OdbcConnection conn, OdbcTransaction transaction) { int count = 0; string sql = "select count(*) from db_class where class_name = '" + tableName + "'"; using (OdbcCommand cmd = new OdbcCommand(sql, conn)) { cmd.Transaction = transaction; count = (int)cmd.ExecuteScalar(); } return count; }
internal OdbcTransaction SetStateExecuting(string method, OdbcTransaction transaction) { // MDAC 69003 if (null != _weakTransaction) { // transaction may exist OdbcTransaction weak = (_weakTransaction.Target as OdbcTransaction); if (transaction != weak) { // transaction doesn't exist if (null == transaction) { // transaction exists throw ADP.TransactionRequired(method); } if (this != transaction.Connection) { // transaction can't have come from this connection throw ADP.TransactionConnectionMismatch(); } // if transaction is zombied, we don't know the original connection transaction = null; // MDAC 69264 } } else if (null != transaction) { // no transaction started if (null != transaction.Connection) { // transaction can't have come from this connection throw ADP.TransactionConnectionMismatch(); } // if transaction is zombied, we don't know the original connection transaction = null; // MDAC 69264 } ConnectionState state = InternalState; if (ConnectionState.Open != state) { NotifyWeakReference(OdbcReferenceCollection.Recover); // recover for a potentially finalized reader state = InternalState; if (ConnectionState.Open != state) { if (0 != (ConnectionState.Fetching & state)) { throw ADP.OpenReaderExists(); } throw ADP.OpenConnectionRequired(method, state); } } return(transaction); }
public TransactionQueue(Database parent) { dbParent = parent; SQLConsole.Data.LLDBA.SERVERINFO svrinfo; svrinfo = parent.GetDatabaseConnector().svrinfo; this._dbo = parent; this._dbo.DBEvent_ReconnectingCloseCause += new Database.ReconnectingCloseCause(_dbo_DBEvent_ReconnectingCloseCause); this._transList = new System.Collections.ArrayList(); this.Atomic = true; this.AutoExecute = false; this.odt = null; this.oc = null; this._errorState = 0; this._lastID = -1; }
OdbcTransaction BeginTransaction(IsolationLevel isolevel) { if (State == ConnectionState.Closed) { throw ExceptionHelper.ConnectionClosed(); } if (transaction == null) { transaction = new OdbcTransaction(this, isolevel); return(transaction); } else { throw new InvalidOperationException(); } }
void Close() { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { lock (this) { // close any associated commands // NOTE: we may 'miss' some if the garbage collector has // already started to destroy them. if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference)linkedCommands [i]; if (wr == null) { continue; } OdbcCommand c = (OdbcCommand)wr.Target; if (c != null) { c.Unlink(); } } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect(hdbc); } // There could be OdbcCommands outstanding (see NOTE above); their // hstmts will have been freed and therefore will be invalid. // However, they will find that their definition of Generation // does not match the connection's, so they won't try and free // those hstmt. if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } FreeHandles(); transaction = null; RaiseStateChange(ConnectionState.Open, ConnectionState.Closed); } }
internal OdbcTransaction Open_BeginTransaction(IsolationLevel isolevel) { OdbcConnection.ExecutePermission.Demand(); CheckState(ADP.BeginTransaction); // MDAC 68323 RollbackDeadTransaction(); if ((null != this.weakTransaction) && this.weakTransaction.IsAlive) // regression from Dispose/Finalize work { throw ADP.ParallelTransactionsNotSupported(this); } //Use the default for unspecified. switch (isolevel) { case IsolationLevel.Unspecified: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: break; case IsolationLevel.Chaos: throw ODBC.NotSupportedIsolationLevel(isolevel); default: throw ADP.InvalidIsolationLevel(isolevel); } ; //Start the transaction OdbcConnectionHandle connectionHandle = ConnectionHandle; ODBC32.RetCode retcode = connectionHandle.BeginTransaction(ref isolevel); if (retcode == ODBC32.RetCode.ERROR) { HandleError(connectionHandle, retcode); } OdbcTransaction transaction = new OdbcTransaction(this, isolevel, connectionHandle); this.weakTransaction = new WeakReference(transaction); // MDAC 69188 return(transaction); }
void Close() { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { // disconnect ret = libodbc.SQLDisconnect(hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw new OdbcException(new OdbcError("SQLDisconnect", OdbcHandleType.Dbc, hdbc)); } FreeHandles(); transaction = null; RaiseStateChange(ConnectionState.Open, ConnectionState.Closed); } }
internal OdbcTransaction SetStateExecuting(string method, OdbcTransaction transaction) { if (this.weakTransaction != null) { OdbcTransaction target = this.weakTransaction.Target as OdbcTransaction; if (transaction != target) { if (transaction == null) { throw ADP.TransactionRequired(method); } if (this != transaction.Connection) { throw ADP.TransactionConnectionMismatch(); } transaction = null; } } else if (transaction != null) { if (transaction.Connection != null) { throw ADP.TransactionConnectionMismatch(); } transaction = null; } ConnectionState internalState = this.InternalState; if (ConnectionState.Open == internalState) { return(transaction); } this.NotifyWeakReference(1); internalState = this.InternalState; if (ConnectionState.Open == internalState) { return(transaction); } if ((ConnectionState.Fetching & internalState) != ConnectionState.Closed) { throw ADP.OpenReaderExists(); } throw ADP.OpenConnectionRequired(method, internalState); }
internal void DisconnectFromDataReaderAndConnection() { // get a reference to the datareader if it is alive OdbcDataReader liveReader = null; if (this.weakDataReaderReference != null) { OdbcDataReader reader; reader = (OdbcDataReader)this.weakDataReaderReference.Target; if (this.weakDataReaderReference.IsAlive) { liveReader = reader; } } // remove reference to this from the live datareader if (liveReader != null) { liveReader.Command = null; } this.transaction = null; if (null != _connection) { _connection.RemoveCommand(this); _connection = null; } // if the reader is dead we have to dismiss the statement if (liveReader == null) { if (_cmdWrapper != null) { _cmdWrapper.Dispose(true); } } }
internal void DisconnectFromDataReaderAndConnection() { // get a reference to the datareader if it is alive OdbcDataReader liveReader = null; if (_weakDataReaderReference != null) { OdbcDataReader reader; reader = (OdbcDataReader)_weakDataReaderReference.Target; if (_weakDataReaderReference.IsAlive) { liveReader = reader; } } // remove reference to this from the live datareader if (liveReader != null) { liveReader.Command = null; } _transaction = null; if (null != _connection) { _connection.RemoveWeakReference(this); _connection = null; } // if the reader is dead we have to dismiss the statement if (liveReader == null) { CloseCommandWrapper(); } // else DataReader now has exclusive ownership _cmdWrapper = null; }
void Close() { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { // close any associated commands if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference)linkedCommands [i]; if (wr == null) { continue; } OdbcCommand c = (OdbcCommand)wr.Target; if (c != null) { c.Unlink(); } } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect(hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } FreeHandles(); transaction = null; RaiseStateChange(ConnectionState.Open, ConnectionState.Closed); } }
internal OdbcTransaction Open_BeginTransaction(IsolationLevel isolevel) { OdbcConnection.ExecutePermission.Demand(); CheckState(ADP.BeginTransaction); // MDAC 68323 RollbackDeadTransaction(); if ((null != this.weakTransaction) && this.weakTransaction.IsAlive) { // regression from Dispose/Finalize work throw ADP.ParallelTransactionsNotSupported(this); } //Use the default for unspecified. switch(isolevel) { case IsolationLevel.Unspecified: case IsolationLevel.ReadUncommitted: case IsolationLevel.ReadCommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Serializable: case IsolationLevel.Snapshot: break; case IsolationLevel.Chaos: throw ODBC.NotSupportedIsolationLevel(isolevel); default: throw ADP.InvalidIsolationLevel(isolevel); }; //Start the transaction OdbcConnectionHandle connectionHandle = ConnectionHandle; ODBC32.RetCode retcode = connectionHandle.BeginTransaction(ref isolevel); if (retcode == ODBC32.RetCode.ERROR) { HandleError(connectionHandle, retcode); } OdbcTransaction transaction = new OdbcTransaction(this, isolevel, connectionHandle); this.weakTransaction = new WeakReference(transaction); // MDAC 69188 return transaction; }
public OdbcCommand(string cmdText, OdbcConnection connection, OdbcTransaction transaction) : this() { CommandText = cmdText; Connection = connection; Transaction = transaction; }
//启动事务处理 /// <summary> /// 启动事务处理 /// </summary> public void BeginTransaction() { _Trans = oleconn.BeginTransaction(IsolationLevel.ReadCommitted);// '在当前事务中启动命令 }
// // DeleteProfile // Deletes profile data from the database for the // specified user name. // private bool DeleteProfile(string username, OdbcConnection conn, OdbcTransaction tran) { // Check for valid user name. if (username == null) throw new ArgumentNullException("User name cannot be null."); if (username.Length > 255) throw new ArgumentException("User name exceeds 255 characters."); if (username.IndexOf(",") > 0) throw new ArgumentException("User name cannot contain a comma (,)."); int uniqueID = GetUniqueID(username, false, true); OdbcCommand cmd1 = new OdbcCommand("DELETE * FROM ProfileData WHERE UniqueID = ?", conn); cmd1.Parameters.Add("@UniqueID", OdbcType.Int).Value = uniqueID; OdbcCommand cmd2 = new OdbcCommand("DELETE * FROM Themes WHERE UniqueID = ?", conn); cmd2.Parameters.Add("@UniqueID", OdbcType.Int).Value = uniqueID; OdbcCommand cmd3 = new OdbcCommand("DELETE * FROM Profiles WHERE UniqueID = ?", conn); cmd3.Parameters.Add("@UniqueID", OdbcType.Int).Value = uniqueID; cmd1.Transaction = tran; cmd2.Transaction = tran; cmd3.Transaction = tran; int numDeleted = 0; // Exceptions will be caught by the calling method. numDeleted += cmd1.ExecuteNonQuery(); numDeleted += cmd2.ExecuteNonQuery(); numDeleted += cmd3.ExecuteNonQuery(); if (numDeleted == 0) return false; else return true; }
private static void PrepareCommand(OdbcCommand cmd, OdbcConnection conn, OdbcTransaction trans, string cmdText, DbParameter[] cmdParms) { if (conn.State != ConnectionState.Open) conn.Open(); cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) cmd.Transaction = trans; cmd.CommandType = CommandType.Text;//cmdType; if (cmdParms != null) { foreach (OdbcParameter parm in cmdParms) cmd.Parameters.Add(parm); } }
public bool Parse() { try { //Fix for mysql. if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL) { this._dbo.GetDatabaseConnector().executeNonQuery("SET AUTOCOMMIT = 0"); this._dbo.GetDatabaseConnector().executeNonQuery("BEGIN"); } odt = this._dbo.GetDatabaseConnector().GetRawConnectionObject().BeginTransaction(); this.oc = new OdbcCommand(); oc.Connection = odt.Connection; oc.Transaction = odt; foreach (string sql in this._transList) { //string tmpsql = this._dbo.CompileSQLToNative(sql); string tmpsql = sql; if ((tmpsql != "") && tmpsql.Length > 2) { if (this._dbo.GetDatabaseConnector().Open() != ERRORCODES.NONE) { throw (new Exception("Database connection lost.")); } oc.CommandText = this._dbo.GetDatabaseConnector().DoTopLevelSqlTranslations(ref tmpsql); oc.ExecuteNonQuery(); } } odt.Commit(); if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL) this._dbo.GetDatabaseConnector().executeNonQuery("COMMIT"); return true; } catch(Exception e) { if(e.Message.IndexOf("parallel transactions") > 0) { // Start new connection and try again. this._dbo = this._dbo.getNewConnection(); this.Parse(); } if(this.dbParent.GetDatabaseConnector().GetRawConnectionObject().State == ConnectionState.Closed) this.dbParent.RaiseDBCloseClause(); try { odt.Rollback(); if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL) this._dbo.GetDatabaseConnector().executeNonQuery("ROLLBACK"); } catch { /**/ } this._errorState = 1; this._errorString = e.Message; return false; } }
internal OdbcTransaction Open_BeginTransaction(System.Data.IsolationLevel isolevel) { ExecutePermission.Demand(); this.CheckState("BeginTransaction"); this.RollbackDeadTransaction(); if ((this.weakTransaction != null) && this.weakTransaction.IsAlive) { throw ADP.ParallelTransactionsNotSupported(this); } switch (isolevel) { case System.Data.IsolationLevel.Unspecified: case System.Data.IsolationLevel.ReadUncommitted: case System.Data.IsolationLevel.ReadCommitted: case System.Data.IsolationLevel.RepeatableRead: case System.Data.IsolationLevel.Serializable: case System.Data.IsolationLevel.Snapshot: { OdbcConnectionHandle connectionHandle = this.ConnectionHandle; ODBC32.RetCode retcode = connectionHandle.BeginTransaction(ref isolevel); if (retcode == ODBC32.RetCode.ERROR) { this.HandleError(connectionHandle, retcode); } OdbcTransaction target = new OdbcTransaction(this, isolevel, connectionHandle); this.weakTransaction = new WeakReference(target); return target; } case System.Data.IsolationLevel.Chaos: throw ODBC.NotSupportedIsolationLevel(isolevel); } throw ADP.InvalidIsolationLevel(isolevel); }
public OdbcCommand(string cmdText, OdbcConnection connection, OdbcTransaction transaction) : this(cmdText, connection) { this.Transaction = transaction; }
internal OdbcTransaction SetStateExecuting(string method, OdbcTransaction transaction) { // MDAC 69003 if (null != weakTransaction) { // transaction may exist OdbcTransaction weak = (weakTransaction.Target as OdbcTransaction); if (transaction != weak) { // transaction doesn't exist if (null == transaction) { // transaction exists throw ADP.TransactionRequired(method); } if (this!= transaction.Connection) { // transaction can't have come from this connection throw ADP.TransactionConnectionMismatch(); } // if transaction is zombied, we don't know the original connection transaction = null; // MDAC 69264 } } else if (null != transaction) { // no transaction started if (null != transaction.Connection) { // transaction can't have come from this connection throw ADP.TransactionConnectionMismatch(); } // if transaction is zombied, we don't know the original connection transaction = null; // MDAC 69264 } ConnectionState state = InternalState; if (ConnectionState.Open != state) { NotifyWeakReference(OdbcReferenceCollection.Recover); // recover for a potentially finalized reader state = InternalState; if (ConnectionState.Open != state) { if (0 != (ConnectionState.Fetching & state)) { throw ADP.OpenReaderExists(); } throw ADP.OpenConnectionRequired(method, state); } } return transaction; }
void Close () { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { // close any associated commands if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference) linkedCommands [i]; if (wr == null) continue; OdbcCommand c = (OdbcCommand) wr.Target; if (c != null) c.Unlink (); } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect (hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Dbc, hdbc); FreeHandles (); transaction = null; RaiseStateChange (ConnectionState.Open, ConnectionState.Closed); } }
public DataTable ExecuteTable(string tableName, string query, OdbcTransaction transaction) { try { OdbcCommand dbCommand = transaction.Connection.CreateCommand(); dbCommand.Transaction = transaction; dbCommand.CommandText = query; OdbcDataAdapter dbDataAdapter = new OdbcDataAdapter(dbCommand); DataTable dataTable = new DataTable(tableName); dbDataAdapter.MissingSchemaAction = MissingSchemaAction.Add; dbDataAdapter.FillSchema(dataTable, SchemaType.Source); dbDataAdapter.Fill(dataTable); return dataTable; } catch (Exception) { transaction.Rollback(); var trace = new System.Diagnostics.StackTrace(true); var frame = trace.GetFrame(0); var method = frame.GetMethod(); return null; } }
public object ExecuteScalar(string query, OdbcTransaction transaction) { OdbcCommand dbCommand = transaction.Connection.CreateCommand(); dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = query; dbCommand.Transaction = transaction; return dbCommand.ExecuteScalar(); }
internal OdbcTransaction SetStateExecuting(string method, OdbcTransaction transaction) { if (this.weakTransaction != null) { OdbcTransaction target = this.weakTransaction.Target as OdbcTransaction; if (transaction != target) { if (transaction == null) { throw ADP.TransactionRequired(method); } if (this != transaction.Connection) { throw ADP.TransactionConnectionMismatch(); } transaction = null; } } else if (transaction != null) { if (transaction.Connection != null) { throw ADP.TransactionConnectionMismatch(); } transaction = null; } ConnectionState internalState = this.InternalState; if (ConnectionState.Open == internalState) { return transaction; } this.NotifyWeakReference(1); internalState = this.InternalState; if (ConnectionState.Open == internalState) { return transaction; } if ((ConnectionState.Fetching & internalState) != ConnectionState.Closed) { throw ADP.OpenReaderExists(); } throw ADP.OpenConnectionRequired(method, internalState); }
public void StartTransaction() { if (connection.State == System.Data.ConnectionState.Open) this.transactionControl = connection.BeginTransaction(); }
OdbcTransaction BeginTransaction (IsolationLevel isolevel) { if (State == ConnectionState.Closed) throw ExceptionHelper.ConnectionClosed (); if (transaction == null) { transaction = new OdbcTransaction (this, isolevel); return transaction; } else throw new InvalidOperationException (); }
public OdbcCommand (string cmdText, OdbcConnection connection, OdbcTransaction transaction) : this (cmdText, connection) { this.Transaction = transaction; }
/// <summary> /// Releases the resources used by this object. /// </summary> private void Dispose(bool isDisposing) { // Check to see if Dispose has already been called. if (this.isDisposed == false) { if (isDisposing) { // Dispose managed resources. if (this.odbcTran != null) { this.odbcTran.Dispose(); this.odbcTran = null; } // Closing the connection will abort (rollback) any pending transactions. if (this.odbcConn != null) { this.odbcConn.Close(); this.odbcConn.Dispose(); this.odbcConn = null; } } } this.isDisposed = true; }
/// <summary> /// 插入数据. /// </summary> /// <param name="conn"></param> private void InsertData(OdbcConnection conn, OdbcTransaction t) { // 创建一个 Command. OdbcCommand insertCommand = conn.CreateCommand(); // 定义需要执行的SQL语句. insertCommand.CommandText = INSERT_SQL; // 注意: 只有加了这一句, 才能事务处理!!! insertCommand.Transaction = t; // 定义要查询的参数. insertCommand.Parameters.Add(new OdbcParameter("@sale_date", TEST_SALE_DATE)); insertCommand.Parameters.Add(new OdbcParameter("@sale_item", TEST_SALE_ITEM)); insertCommand.Parameters.Add(new OdbcParameter("@sale_money", 100000)); // ExecuteNonQuery 方法,表明本次操作,不是一个查询的操作。将没有结果集合返回. // 返回的数据,将是 被影响的记录数. int insertRowCount = insertCommand.ExecuteNonQuery(); Console.WriteLine("尝试插入数据, 结果造成了{0}条记录的插入。", insertRowCount); }
/// <summary> /// Starts a new ADO.NET transaction using the open connection object of this class. /// Opens the connection if it isn't already open. /// No nesting allowed, throws exception if the transaction is already pending. /// </summary> /// <remarks>Uses default <see cref="IsolationLevel"/>.</remarks> public void BeginTransaction() { if (this.defaultTransactionIsolationLevel != null) { BeginTransaction(this.defaultTransactionIsolationLevel.Value); } else { if (this.isTransactionPending) throw new InvalidOperationException(Messages.ConnectionProvider_TranAlreadyPending); if (!IsOpen) OpenConnection(); this.odbcTran = this.odbcConn.BeginTransaction(); this.isTransactionPending = true; } }
public bool Queue(string sql) { if(this.AutoExecute == true) { if (this.odt == null) { //Fix for mysql. if (this._dbo.GetDatabaseConnector().getDBType() == DATABASETYPES.MYSQL) { this._dbo.GetDatabaseConnector().executeNonQuery("SET AUTOCOMMIT = 0"); this._dbo.GetDatabaseConnector().executeNonQuery("START TRANSACTION"); } this.odt = this._dbo.GetDatabaseConnector().GetRawConnectionObject().BeginTransaction(IsolationLevel.RepeatableRead); } if (this.oc == null) { this.oc = new OdbcCommand(); this.oc.CommandType = CommandType.Text; this.oc.Connection = this.odt.Connection; this.oc.Transaction = this.odt; } try { string tmpsql = sql; //if (this._dbo.GetDatabaseConnector().Open() != ERRORCODES.NONE) //{ // throw (new Exception("Database connection lost.")); //} oc.CommandText = this._dbo.GetDatabaseConnector().DoTopLevelSqlTranslations(ref tmpsql); oc.ExecuteNonQuery(); oc.CommandText = this._dbo.GetDatabaseProvider().buildGetLastInsertID(); try { this._lastID = Convert.ToInt32(oc.ExecuteScalar()); } catch (Exception e) { if (this.dbParent.GetDatabaseConnector().GetRawConnectionObject().State == ConnectionState.Closed) this.dbParent.RaiseDBCloseClause(); this._lastID = -1; this._errorString = e.Message + "\r\n\r\n" + e.StackTrace; } //this._lastID = 999; //this._errorState = 0; return true; } catch(Exception e) { System.Diagnostics.Debug.Print(e.Message); if (this.dbParent.GetDatabaseConnector().GetRawConnectionObject().State == ConnectionState.Closed) this.dbParent.RaiseDBCloseClause(); this._errorState = 1; return false; } } else this._transList.Add(sql); return true; }
/// <summary>トランザクション開始</summary> /// <param name="iso">分離レベル(内部プロバイダによるので全てサポート)</param> public override void BeginTransaction(DbEnum.IsolationLevelEnum iso) { // 分離レベル設定のチェック if (iso == DbEnum.IsolationLevelEnum.NoTransaction) { // トランザクションを開始しない(nullのまま)。 } else if (iso == DbEnum.IsolationLevelEnum.DefaultTransaction) { // 規定の分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(); } else if (iso == DbEnum.IsolationLevelEnum.ReadUncommitted) { // 非コミット読み取りの分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(IsolationLevel.ReadUncommitted); } else if (iso == DbEnum.IsolationLevelEnum.ReadCommitted) { // コミット済み読み取りの分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(IsolationLevel.ReadCommitted); } else if (iso == DbEnum.IsolationLevelEnum.RepeatableRead) { // 反復可能読み取りの分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(IsolationLevel.RepeatableRead); } else if (iso == DbEnum.IsolationLevelEnum.Serializable) { // 直列化可能の分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(IsolationLevel.Serializable); } else if (iso == DbEnum.IsolationLevelEnum.Snapshot) { // スナップショット分離レベルでトランザクションを開始する。 this._tx = this._cnn.BeginTransaction(IsolationLevel.Snapshot); } else if (iso == DbEnum.IsolationLevelEnum.User) { // 無効な分離レベル(ユーザ指定)。 throw new ArgumentException( PublicExceptionMessage.DB_ISO_LEVEL_PARAM_ERROR_USR); } else if (iso == DbEnum.IsolationLevelEnum.NotConnect) { // 2009/03/29 -- 追加したNotConnectの対応(このコードブロック)。 // 無効な分離レベル(NotConnect指定)。 throw new ArgumentException( PublicExceptionMessage.DB_ISO_LEVEL_PARAM_ERROR_NC); } else { // 通らない予定 } // 分離レベル(iso)をメンバ変数に保存 _iso = iso; }
/// <summary>トランザクションのロールバック</summary> /// <remarks>必要に応じて利用する。</remarks> public override void RollbackTransaction() { // Txオブジェクトの存在チェック if (this._tx == null) { // nullのためなにもしない。 } else { // トランザクションのロールバック this._tx.Rollback(); // nullクリア this._tx = null; } }
public void BeginTransaction(IsolationLevel level) { _trans = _con.BeginTransaction(level); }
protected object EjecutarODBC(object Sql, TipoRetorno TipoRetorno, Transaccion Transaccion, string CnnStrDB, string nombreODBC) { switch (Sql.GetType().FullName.ToString()) { case "System.String[]": sqls = (string[])Sql; break; default: //case "System.String": sqls = new String[] { (string)Sql }; break; } cantReg = new int[sqls.Length]; switch (Transaccion) { case (Transaccion.Acepta): usaTransaccion = (sqls.Length > 1); break; case (Transaccion.NoAcepta): usaTransaccion = false; break; default: //(Transaccion.Usa): usaTransaccion = true; break; } if (usaTransaccion) ODBCTransaccion = ODBCConexion.BeginTransaction(); try { ODBCConexion = new OdbcConnection("dsn=" + nombreODBC + ";uid=" + sesion.Usuario.Id + ";pwd=" + sesion.Usuario.Password + ";"); ODBCConexion.Open(); ODBCComando = new OdbcCommand(Sql.ToString(), ODBCConexion); ds = new DataSet(); for(i = 0; i < sqls.Length; i++) { System.Diagnostics.Debug.WriteLine(sqls[i]); ODBCAdapter = new OdbcDataAdapter(sqls[i], ODBCConexion); if(usaTransaccion) { ODBCAdapter.SelectCommand.Transaction = ODBCTransaccion; } ODBCAdapter.SelectCommand.CommandTimeout = 90; if(i == 0) { ODBCAdapter.Fill(ds); } else { ds.Tables.Add(); ODBCAdapter.Fill(ds.Tables[ds.Tables.Count - 1]); } } return ds; } catch (Exception ex) { throw new CondecoEX.db.Conexion(ex); } }
private static void PrepareCommand(OdbcCommand cmd, OdbcConnection conn, OdbcTransaction trans, string cmdText, OdbcParameter[] cmdParms) { if (conn.State != ConnectionState.Open) conn.Open(); cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) cmd.Transaction = trans; cmd.CommandType = CommandType.Text;//cmdType; if (cmdParms != null) { foreach (OdbcParameter parameter in cmdParms) { if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) && (parameter.Value == null)) { parameter.Value = DBNull.Value; } cmd.Parameters.Add(parameter); } } }
/// <summary>トランザクションのコミット</summary> /// <remarks>必要に応じて利用する。</remarks> public override void CommitTransaction() { // Txオブジェクトの存在チェック if (this._tx == null) { // nullのためなにもしない。 } else { // トランザクションのコミット this._tx.Commit(); // nullクリア this._tx = null; } }
/// <summary> /// Starts a new ADO.NET transaction using the open connection object of this class. /// Opens the connection if it isn't already open. /// No nesting allowed, throws exception if the transaction is already pending. /// </summary> /// <param name="isolationLevel">The transaction isolation level.</param> public void BeginTransaction(IsolationLevel isolationLevel) { if (this.isTransactionPending) throw new InvalidOperationException(Messages.ConnectionProvider_TranAlreadyPending); if (!IsOpen) OpenConnection(); this.odbcTran = this.odbcConn.BeginTransaction(isolationLevel); this.isTransactionPending = true; }
void Close () { OdbcReturn ret = OdbcReturn.Error; if (State == ConnectionState.Open) { lock(this) { // close any associated commands // NOTE: we may 'miss' some if the garbage collector has // already started to destroy them. if (linkedCommands != null) { for (int i = 0; i < linkedCommands.Count; i++) { WeakReference wr = (WeakReference) linkedCommands [i]; if (wr == null) continue; OdbcCommand c = (OdbcCommand) wr.Target; if (c != null) c.Unlink (); } linkedCommands = null; } // disconnect ret = libodbc.SQLDisconnect (hdbc); } // There could be OdbcCommands outstanding (see NOTE above); their // hstmts will have been freed and therefore will be invalid. // However, they will find that their definition of Generation // does not match the connection's, so they won't try and free // those hstmt. if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Dbc, hdbc); FreeHandles (); transaction = null; RaiseStateChange (ConnectionState.Open, ConnectionState.Closed); } }
private static void ExecuteSQL(string sql, OdbcConnection conn, OdbcTransaction transaction) { using (OdbcCommand cmd = new OdbcCommand(sql, conn)) { cmd.Transaction = transaction; cmd.ExecuteNonQuery(); } }