ORA-01453: SET TRANSACTION 必须是事务处理的第一个语句系统架构:
使用了.net remoting技术,客户端向服务器发送数据,服务器将数据保存到ora中,但是如果用户量大的时候,就会出现这个错误。下面是事务处理方法:
public bool Transaction( string[] inSQL, string inConnString )
{
if ( inSQL.Length < 1 )
return true; bool rtn = false; OracleConnection conn = new OracleConnection( inConnString );
try
{
conn.Open();
OracleTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted); try
{
for( int i = 0; i < inSQL.Length; i++ )
{
SQLRowIndex = i;
DBErrorSQL = inSQL[i];
if ( inSQL[ i ].CompareTo( "" ) > 0 )
{
OracleCommand OracleCommand = new OracleCommand();
OracleCommand.Connection = conn;
OracleCommand.Transaction = trans; OracleCommand.CommandText = inSQL[i];
OracleCommand.ExecuteNonQuery();
}
}
trans.Commit();
rtn = true;
}
catch( Exception e )
{
try
{
trans.Rollback();
}
catch(Exception errr)
{
SaveErrorToLog( "事务回滚错误 " + errr.Message, DBErrorSQL );
}
SaveErrorToLog( "事务处理错误 " + e.Message, DBErrorSQL );
rtn = false;
}
finally
{
conn.Close();
}
}
catch(Exception er)
{
SaveErrorToLog( er.Message, "事务处理错误" );
rtn = false;
}
finally
{
conn.Dispose();
}
return rtn;
}
使用了.net remoting技术,客户端向服务器发送数据,服务器将数据保存到ora中,但是如果用户量大的时候,就会出现这个错误。下面是事务处理方法:
public bool Transaction( string[] inSQL, string inConnString )
{
if ( inSQL.Length < 1 )
return true; bool rtn = false; OracleConnection conn = new OracleConnection( inConnString );
try
{
conn.Open();
OracleTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted); try
{
for( int i = 0; i < inSQL.Length; i++ )
{
SQLRowIndex = i;
DBErrorSQL = inSQL[i];
if ( inSQL[ i ].CompareTo( "" ) > 0 )
{
OracleCommand OracleCommand = new OracleCommand();
OracleCommand.Connection = conn;
OracleCommand.Transaction = trans; OracleCommand.CommandText = inSQL[i];
OracleCommand.ExecuteNonQuery();
}
}
trans.Commit();
rtn = true;
}
catch( Exception e )
{
try
{
trans.Rollback();
}
catch(Exception errr)
{
SaveErrorToLog( "事务回滚错误 " + errr.Message, DBErrorSQL );
}
SaveErrorToLog( "事务处理错误 " + e.Message, DBErrorSQL );
rtn = false;
}
finally
{
conn.Close();
}
}
catch(Exception er)
{
SaveErrorToLog( er.Message, "事务处理错误" );
rtn = false;
}
finally
{
conn.Dispose();
}
return rtn;
}
Cause: A transaction was not processed properly because the SET
TRANSACTION statement was not the first statement.
Action: Commit or roll back the current transaction before using the statement
SET TRANSACTION.
其它情况是否应当执行
trans.Rollback();呢?(我不知道语句是否应该这样写)