473,498 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2.0: database application with transactions

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/
Oct 1 '06 #1
6 1578


"RAM" <r_********@poczta.onet.plwrote in message
news:eH**************@TK2MSFTNGP04.phx.gbl...
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!)
You should not hold database transactions open across page postbacks. If
you begin a transaction in Page_Load, you commit it or roll back before you
leave the method.

David

Oct 2 '06 #2
RAM
Thanks for answer....

Uzytkownik "David Browne" <davidbaxterbrowne no potted me**@hotmail.com>
napisal w wiadomosci news:%2***************@TK2MSFTNGP03.phx.gbl...
You should not hold database transactions open across page postbacks. If
you begin a transaction in Page_Load, you commit it or roll back before
you leave the method.
Why? Could you explain me please. My transactions are complicated, they
require complex user's interaction, maybe sometimes
on a number of ASP.NET pages. How to rollback the transaction when the user
cancels work pressing Back returning to Default.aspx? Please help.
/RAM/
Oct 2 '06 #3
RAM wrote:
Thanks for answer....

Uzytkownik "David Browne" <davidbaxterbrowne no potted
me**@hotmail.comnapisal w wiadomosci
news:%2***************@TK2MSFTNGP03.phx.gbl...
You should not hold database transactions open across page
postbacks. If you begin a transaction in Page_Load, you commit it
or roll back before you leave the method.

Why? Could you explain me please. My transactions are complicated,
they require complex user's interaction, maybe sometimes
on a number of ASP.NET pages. How to rollback the transaction when
the user cancels work pressing Back returning to Default.aspx? Please
help. /RAM/
One golden rule: NEVER EVER have user interaction during a db
transaction. NEVER.

This is because a user can walk away to the coffee machine or go home
and the transaction will stall, blocking other threads.

What you should do is collect data in-memory, and when the user is
done specifying things and ready to save, you THEN start a transaction
and persist all data. This also solves it when the user cancels halfway
through a bunch of screens, you never saved anything.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 2 '06 #4
RAM
Thanks.

Uzytkownik "Frans Bouma [C# MVP]" <pe******************@xs4all.nlnapisal w
wiadomosci news:xn***************@news.microsoft.com...
What you should do is collect data in-memory, and when the user is
done specifying things and ready to save, you THEN start a transaction
and persist all data. This also solves it when the user cancels halfway
through a bunch of screens, you never saved anything.
OK.
Suppose I have a sheet of cells with some editable text data (to be
implemented using data list) and I would like to have a whole-list-changes
transaction (NOT row-level). Do you mean that I should save changes
considering modifications of rows instead of using
OnEdit/Update/Cancel/DeleteCommand attributes of DataList? (In case of
row-level changes I could write proper UPDATE/DELETE...)
Please help. Thank you very much!
/RAM/
Oct 3 '06 #5
RAM wrote:
Thanks.

Uzytkownik "Frans Bouma [C# MVP]" <pe******************@xs4all.nl>
napisal w wiadomosci news:xn***************@news.microsoft.com...
What you should do is collect data in-memory, and when the user is
done specifying things and ready to save, you THEN start a
transaction and persist all data. This also solves it when the user
cancels halfway through a bunch of screens, you never saved
anything.

OK.
Suppose I have a sheet of cells with some editable text data (to be
implemented using data list) and I would like to have a
whole-list-changes transaction (NOT row-level). Do you mean that I
should save changes considering modifications of rows instead of
using OnEdit/Update/Cancel/DeleteCommand attributes of DataList? (In
case of row-level changes I could write proper UPDATE/DELETE...)
Please help. Thank you very much!
/RAM/
You should track the changes in some datastructure. I'm not sure what
datastructure you're using to store the values in when you read them
from the db, perhaps a datatable. When the user makes changes, you
track the changes in a datastructure, which you then use later on to
persist to the DB.

That's the way you should go. There's no other way, as you should
never go the route of having one big transaction for the whole screen
DURING the edit process, which can take for example a whole morning.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 3 '06 #6
RAM
(Sorry for my English...)

Uzytkownik "Frans Bouma [C# MVP]" <pe******************@xs4all.nlnapisal w
wiadomosci news:xn***************@news.microsoft.com...
You should track the changes in some datastructure. I'm not sure what
datastructure you're using to store the values in when you read them
from the db, perhaps a datatable.
Yes, I use DataTable.
>When the user makes changes, you
track the changes in a datastructure, which you then use later on to
persist to the DB.
I tried to use DataTable assigned to DataSource attribute. I don't
understand why I failed to obtain DataSource value in next event after
DataBind - I receive null. Could you explain me this phenomena?

Thus, I decided to use my own DataTable object and maintain its rows in
DataList commands' procedures. Additionally I 'log' SQL instructions
(UPDATE/DELETE/INSERT) in string field. I don't like this solution because
it is quite complicated (Microsoft's support for transactional applications
in .NET is not enough for me if I cannot make modifications of a list
control to be a database transaction
I would prefer to use solution with DataSource attribute if it is posiible.
Please help. Maybe it makes my code simpler if rows of DataSource are
maintained automatically (are they?).
That's the way you should go. There's no other way, as you should
never go the route of having one big transaction for the whole screen
DURING the edit process, which can take for example a whole morning.
Wise. Thanks.
Oct 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7444
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
23
2788
by: ajikoe | last post by:
Hello I need to build table which need searching data which needs more power then dictionary or list in python, can anyone help me what kind of database suitable for python light and easy to learn....
2
339
by: Simon Harvey | last post by:
Hi all, Can someone please reasure me that it is entirely possible to use the Data Access Application in large applications - even those that require transactions? I have a friend who is...
13
2320
by: Robin Haswell | last post by:
Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules...
4
2954
by: DeepDiver | last post by:
I am developing an inventory database in SQL Server. I realize there are many commercial (as well as some non-commercial) inventory offerings, but my client has specific requirements that would...
2
1864
by: RAM | last post by:
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...
10
1930
by: giraffeboy | last post by:
Hi there, I'm having a problem with the Python db api, using MySQL. I've written a program with a GUI using wxPython, the GUI is contained in main.py which imports another module - reports.py....
3
2878
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it...
5
3475
by: Roger | last post by:
backup log testdb with truncate_only DBCC SHRINKFILE (testdb_log, 100) WITH NO_INFOMSGS backup database testdb to disk = '\\DC01\Backups\DB01\testdb.bak' with init and does the shrinkfile...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.