当我尝试像其他任何交易(drop sequence name
)一样运行insert, update, delete
时,它不起作用。如何从C#程序中删除和创建序列?
这是代码
public static bool executeQuery(string query)
{
bool success = false;
DBConnection db = new DBConnection();
db.Connect();
if (db.GetConnectionState())
{
db.SetSql(query);
if (db.ExecuteTransactions())
success = true;
else
success = false;
}
else
success = false;
return success;
}
来自DBConnection类的方法ExecuteTransactions()
和SetSql()
,
private OracleConnection connection;
private OracleCommand command;
private bool autoDisconnect;
public bool ExecuteTransactions()
{
OracleTransaction transaction = null;
bool success = false;
try
{
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
command.Connection = connection;
command.Transaction = transaction;
if (command.ExecuteNonQuery() > 0)
{
transaction.Commit();
success = true;
}
else
{
transaction.Rollback();
success = false;
}
}
catch (Exception ex)
{
success = false;
autoDisconnect = true;
throw new Exception(ex.ToString());
}
//Cleaning
finally
{
if (transaction != null)
{
transaction.Dispose();
}
if (autoDisconnect)
{
if (command.Parameters.Count > 0)
{
foreach (OracleParameter pram in command.Parameters)
{
if (pram.Direction != ParameterDirection.ReturnValue)
pram.Dispose();
}
}
if (command != null)
{
command.Dispose();
}
Dispose();
}
}
return success;
}
public void SetSql(string sql)
{
command = new OracleCommand(sql);
command.BindByName = true;
}
我不确定问题是否是SetSql()
方法,因为drop sequence
不是OracleCommand?或者,如果是ExecuteTransactions()
方法,则在if (command.ExecuteNonQuery() > 0)
谢谢!
编辑:这是错误
An exception of type 'System.Exception' occurred in TDS1.exe but was not handled in user code
Additional information: System.InvalidOperationException: OracleCommand.CommandText is invalid
at Oracle.ManagedDataAccess.Client.OracleCommand.DoPreExecuteProcessing(OracleDependencyImpl orclDependencyImpl, Boolean bXmlQuerySave)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
它在if (command.ExecuteNonQuery > 0)