Last post Apr 10, 2015 08:09 AM by Mikesdotnetting
Apr 09, 2015 09:20 AM|fszdp123|LINK
I am trying to use sql server database transaction in webpages site, but can not find any documents about it. Dose the Database object surport for transaction in webpages? Or I have to use ADO.NET objects in Webpages? How can I do that?
thanks in advance
Apr 09, 2015 09:33 AM|Lokesh B R|LINK
Check this sample
using (SqlConnection connection = new SqlConnection(connectionString))
// Start a local transaction.
SqlTransaction sqlTran = connection.BeginTransaction();
// Enlist a command in the current transaction.
SqlCommand command = connection.CreateCommand();
command.Transaction = sqlTran;
// Execute two separate commands.
"INSERT INTO Production.ScrapReason(Name) VALUES('Wrong size')";
"INSERT INTO Production.ScrapReason(Name) VALUES('Wrong color')";
// Commit the transaction.
Console.WriteLine("Both records were written to database.");
catch (Exception ex)
// Handle the exception if the transaction fails to commit.
// Attempt to roll back the transaction.
catch (Exception exRollback)
// Throws an InvalidOperationException if the connection
// is closed or the transaction has already been rolled
// back on the server.
Apr 10, 2015 08:09 AM|Mikesdotnetting|LINK
To answer your question, the Database helper does not support Transactions. You will have to use ADO.NET instead.