Can anyone tell me how to work with database transactions in a web service.
Can anyone please give me a sample code.
Dear Merline Martina,
Here is a sample code which explains about the database transactions in a
web service.
[Web Method]
public string adduser( string UserName, string UserPassword)
{
string uname,upassword;
uname=UserNmae;
upassword=userPassword;
string mycon=”Intial Catalog=test;Data Source= johnpaul\DBTEST; Integrated
security =SSPI”;
//declare a sql connection by building a object named myconnection
SqlConnection mysqlConnection =new SqlConnection(mycon);
// declare sql command by using a object named mycommand
SqlCommand mysqlCommand = new SqlCommand();
// using sql transaction class
SqlTransaction myTrans;
// Open the connection.
mysqlConnection.Open();
// Assign the connection property.
mysqlCommand.Connection = mysqlConnection;
// Begin the transaction.
myTrans = myConnection.BeginTransaction();
// Assign transaction object for a pending local transaction
mysqlCommand.Transaction = myTrans;
try
{
// Insert the user record.
mysqlCommand.CommandText = "Insert into useraccount VALUES
('"+uname+"','"+ufamily+"')";
mysqlCommand.ExecuteNonQuery();
// pass the data .transaction complete
myTrans.Commit();
return "transaction completed";
}
catch(Exception e)
{
// transaction cancel
myTrans.Rollback();
return e.ToString()+"transaction abort";
}
}
Rgds,
John Paul. A
> Can anyone tell me how to work with database transactions in a web service.
> Can anyone please give me a sample code.
Merline Martina - 23 Nov 2004 11:21 GMT
Thanks...
Can you give me few links please...
> Dear Merline Martina,
> Here is a sample code which explains about the database transactions in a
[quoted text clipped - 51 lines]
> > Can anyone tell me how to work with database transactions in a web service.
> > Can anyone please give me a sample code.
John Paul. A - 23 Nov 2004 11:53 GMT
Have a look at this page.
Web Services Transaction (WS-Transaction
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html
/ws-transaction.asp
Rgds,
John Paul. A
> Thanks...
> Can you give me few links please...
[quoted text clipped - 54 lines]
> > > Can anyone tell me how to work with database transactions in a web service.
> > > Can anyone please give me a sample code.