|
[C#] 源代码网推荐<%@ WebService Language="C#" Class="Orders" %> 源代码网推荐<%@ Assembly name="System.EnterpriseServices,
Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> 源代码网推荐using System; 源代码网推荐using System.Data; 源代码网推荐using System.Data.SqlClient; 源代码网推荐using System.Web.Services; 源代码网推荐using System.EnterpriseServices;
public class Orders : WebService 源代码网推荐{ 源代码网推荐[ WebMethod(TransactionOption=TransactionOption.RequiresNew)] 源代码网推荐public int DeleteAuthor(string lastName) 源代码网推荐{ 源代码网推荐String deleteCmd = "DELETE FROM authors WHERE au_lname="" + 源代码网推荐lastName + """ ; 源代码网推荐String exceptionCausingCmdSQL = "DELETE FROM NonExistingTable WHERE 源代码网推荐au_lname="" + lastName + """ ;
SqlConnection sqlConn = new SqlConnection( 源代码网推荐"Persist Security Info=False;Integrated Security=SSPI;database=pubs;server=myserver");
SqlCommand deleteCmd = new SqlCommand(deleteCmdSQL,sqlConn); 源代码网推荐SqlCommand exceptionCausingCmd = new 源代码网推荐SqlCommand(exceptionCausingCmdSQL,sqlConn);
// This command should execute properly. 源代码网推荐deleteCmd.Connection.Open(); 源代码网推荐deleteCmd.ExecuteNonQuery();
// This command results in an exception, so the first command is 源代码网推荐// automatically rolled back. Since the XML Web service method is 源代码网推荐// participating in a transaction, and an exception occurs, ASP.NET 源代码网推荐// automatically aborts the transaction. The deleteCmd that 源代码网推荐// executed properly is rolled back.
int cmdResult = exceptionCausingCmd.ExecuteNonQuery();
sqlConn.Close();
return cmdResult; 源代码网推荐} 源代码网推荐} 源代码网推荐[Visual Basic] 源代码网推荐<%@ WebService Language="VB" Class="Orders" %> 源代码网推荐<%@ assembly name="System.EnterpriseServices" %>
Imports System 源代码网推荐Imports System.Data 源代码网推荐Imports System.Data.SqlClient 源代码网推荐Imports System.Web.Services 源代码网推荐Imports System.Web.Util 源代码网推荐Imports System.EnterpriseServices
Public Class Orders
<WebMethod(TransactionOption:=TransactionOption.RequiresNew)> _ 源代码网推荐Public Function DeleteAuthor (lastName as String) as Integer
Dim deleteCmdSQL As String = "DELETE FROM authors WHERE au_lname="" + _ 源代码网推荐lastName + """ 源代码网推荐Dim exceptionCausingCmdSQL As String = "DELETE FROM " + _ 源代码网推荐"NonExistingTable WHERE au_lname="" + lastName + """
Dim sqlConn As SqlConnection = New SqlConnection( _ 源代码网推荐"Persist Security Info=False;Integrated Security=SSPI;database=pubs;server=myserver")
Dim deleteCmd As SqlCommand = New SqlCommand(deleteCmdSQL,sqlConn) 源代码网推荐Dim exceptionCausingCmd As SqlCommand = New _ 源代码网推荐SqlCommand(exceptionCausingCmdSQL,sqlConn)
" This command should execute properly. 源代码网推荐deleteCmd.Connection.Open() 源代码网推荐deleteCmd.ExecuteNonQuery()
" This command results in an exception, so the first command is 源代码网推荐" automatically rolled back. Since the XML Web service method is 源代码网推荐" participating in a transaction, and an exception occurs, ASP.NET 源代码网推荐" automatically aborts the transaction. The deleteCmd that 源代码网推荐" executed properly is rolled back.
Dim cmdResult As Integer = exceptionCausingCmd.ExecuteNonQuery() 源代码网推荐sqlConn.Close()
Return cmdResult 源代码网推荐End Function 源代码网推荐End Class
|