如果波纹管代码正确,请告诉我。 我的意思是关闭已关闭并处理,并且交易已关闭并处置并在发生异常时回滚。 欢迎任何其他建议。
谢谢你, Adrya
using (FbConnection c = new FbConnection(m_connection))
{
c.Open();
using (FbTransaction trans = c.BeginTransaction())
{
using (FbCommand cmd = new FbCommand("DELETE_MESSAGES_QUEUE", c, trans))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("INQUEUENAME", queueName);
cmd.ExecuteNonQuery();
}
using (FbCommand cmd = new FbCommand("DELETE_QUEUE", c, trans))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("INQUEUENAME", queueName);
cmd.ExecuteNonQuery();
}
trans.Commit();
}
}
答案 0 :(得分:2)
是的,这段代码看起来很不错。
答案 1 :(得分:0)
我可能会使用事务范围,但不确定处理事务是否会将事务卷回来,但是事先确定了TransactionScope。
using (var scope = new TransactionScope())
using (var c = new FbConnection(m_connection))
{
using (var cmd = new FbCommand("DELETE_MESSAGES_QUEUE", c))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("INQUEUENAME", queueName);
cmd.ExecuteNonQuery();
}
using (var cmd = new FbCommand("DELETE_QUEUE", c))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("INQUEUENAME", queueName);
cmd.ExecuteNonQuery();
}
scope.Complete();
}
答案 2 :(得分:0)