扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
[C#] <%@ WebService Language="C#" Class="Orders" %> [Visual Basic] <%@ WebService Language="VB" Class="Orders" %> |
<%@ Assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %> |
[C#] using System.Web.Services; using System.EnterpriseServices; [Visual Basic] Imports System.Web.Services Imports System.EnterpriseServices |
[C#] [ WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int DeleteAuthor(string lastName) [Visual Basic] < WebMethod(TransactionOption:=TransactionOption.RequiresNew)> _ Public Function DeleteAuthor(lastName As String) As Integer |
[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 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者