該存儲過程使用 BEGIN TRANSACTION
如何編寫事務性
以下示例代碼顯示了三個服務性
using System;
using System
[Transaction(TransactionOption
public class Transfer : ServicedComponent
{
[AutoComplete]
public void Transfer( string toAccount
string fromAccount
{
try
{
// Perform the debit operation
Debit debit = new Debit();
debit
// Perform the credit operation
Credit credit = new Credit();
credit
}
catch( SqlException sqlex )
{
// Handle and log exception details
// Wrap and propagate the exception
throw new TransferException(
}
}
}
[Transaction(TransactionOption
public class Credit : ServicedComponent
{
[AutoComplete]
public void CreditAccount( string account
{
try
{
using( SqlConnection conn = new SqlConnection(
{
SqlCommand cmd = new SqlCommand(
cmd
cmd
cmd
conn
cmd
}
}
}catch( SqlException sqlex ){
// Log exception details here
throw; // Propagate exception
}
}
[Transaction(TransactionOption
public class Debit : ServicedComponent
{
public void DebitAccount( string account
{
try
{
using( SqlConnection conn = new SqlConnection(
{
SqlCommand cmd = new SqlCommand(
cmd
cmd
cmd
conn
cmd
}
}
catch (SqlException sqlex)
{
// Log exception details here
throw; // Propagate exception back to caller
}
}
}
[
From:http://tw.wingwit.com/Article/program/net/201311/15087.html