[Transaction(TransactionOption.Required)]
public class test : System.EnterpriseServices.ServicedComponent
{
public test()
{
}//end test
/// <summary>
/// 查询语句
///如果事物失败则撤销事务并回滚
/// </summary>
public void gettable()
{
try
{
conn = string.Empty;
System.Data.SqlClient.SqlConnection con= new SqlConnection(conn);
System.Data.SqlClient.SqlCommand cmd = new SqlCommand();
cmd.CommandText = "drop table";//一系列删除更新等操作
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ContextUtil.SetComplete();//事务完成
}//end try
catch(Exception ex)
{
if(ContextUtil.IsInTransaction) //如果事务在处理中
{
ContextUtil.SetAbort() ;//撤销事务
}//end if
throw ex;
}//end catch
}//end gettable
}//end test