Tuesday, June 12, 2007

Transactional Webservice in ASP.NET

Transactional Webservice in ASP.NET
=============================


You can make a transactional webservice using dot net


using System;
using System.Data.SqlClient;
using System.Web.Services;
//assembly required for transactional webservice
using System.EnterpriseServices;

public class myWebServiceTransaction {

//data source details
private static string connectionString = "Data Source=(local);Initial Catalog=Northwind;user ID=sa";

//attribute required for webservice transaction
[WebMethod(TransactionOption=TransactionOption.RequiresNew)]
public void webServiceTransaction() {

// Create the connection.
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("DELETE * FROM myTable", con);

con.Open();
cmd.ExecuteNonQuery();
con.Close();


// database actions are commited if there is no error
}

}

No comments: