2.0: design of database application with transactions

R

RAM

Hello,
(Sorry for my English...)
I am learning .NET 2.0 (C#, ASP.NET, ADO.NET etc.).
I need to write a database application (SQL Server) consisting of a number
of database transactions (like accounting system). Each of these
transactions has enty in menu, parameters screen (.aspx page), some logic
(probably implemented in code-behind), and results screen (could be
same.aspx page). I need a good design, some ideas of experienced
programmers.
My idea is the following: I will use web.sitemap to implement menu, and
X.aspx/X.aspx.cs to implement transactions. In Default.aspx I have a menu
using sitemap data source. In X.aspx.cs I have written

protected void Page_Load(...)
{
if (!IsPostBack)
{
...
transaction = connection.BeginTransaction("...");
}
}
protected void SaveButton_Click(...)
{
...
transaction.Commit();
}

One of my problems is that I don't know where to put Rollback. It is not
enough (I think) to create CancelButton because user could press Back button
in his/her browser :-(. I can put Rollback code into Default.aspx.cs
Page_Load (to be called when new menu option is executed), but I don't like
this idea.
Could you help me please to correctly design my application? (I must use
ASP.NET!)
Thank you.
/RAM/
 
M

Mark Fitzpatrick

Usually you would create the transaction before you began doing any queries
or data manipulation. Then, as handle each item, check to see the result
that you're getting back from SQL Server and, if no errors are reported,
then move forward to the next item. If they're all OK then commit. If any of
them are false then you have to rollback the transaction immediately and
break out of the process since any further actionswould, of course, depend
on the success of the previous actions.

I often work with transactions in SQL Server stored procedures as well to
help ensure that things get handled efficiently and use the return parameter
of a stored procedure to let me know if things proceeded well (such as the
transaction was committed) or failed and was rolled back so I can then
rollback my asp.net transaction. I try not to use ASP.Net transactions
whenever I'm able though as they seem to have more overhead than using
built-in SQL Server transactions.
 
R

RAM

Thanks.

U¿ytkownik "Mark Fitzpatrick said:
... If they're all OK then commit. If any of them are false then you have
to rollback the transaction immediately and break out of the process since
any further actionswould, of course, depend on the success of the previous
actions.

OK, but I nedd to give to the user opportunity to manually cancel work.
Where to put Rollback to be called also when user pressed Back browser's
button.
Please help. Thank you.
/RAM/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top