• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Make a transaction between to pages.

Hi!

For a project using LINQ to entity and ASP.Net(and ms SQL)

I've a transaction that must be done in one time:

displaying form
editing
submitting page

And I will this is a single transaction, how can I do it?
0
Nargzul
Asked:
Nargzul
  • 5
  • 5
  • 2
1 Solution
 
RiteshShahCommented:
can't you do something like display the form, let user edit and keep everything in memory (view state or session etc.) and while submitting, open one transaction, execute statements you wants and commit transaction if it is successful.

0
 
NargzulAuthor Commented:
We don't want that 2 users can open the edition page of the same product. So we want that the row is locked.
0
 
chapmandewCommented:
This is a BAD idea to do at the database level...if you begin a tran on one page and end it on another, there are a TON of things that could go wrong to hose your db.  For starters, you're leaving a transaction open and depending on the user to commit it.  Really, it seems, you only need the transaction portion when you are submitting the page.  Anything else, and you should write logic to not let other people (users) edit the data while it is being displayed (checked out)...this could be as simple as adding a bit flag to a table an set it to 1 when someone is viewing and editing data.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
NargzulAuthor Commented:
Why manage it in the logical part if the database can do it? We assure that our data are consistent, by exemple if one time we got a webservice, ...

The structure of the database is fixed, and it's only for a educational goal.
0
 
chapmandewCommented:
Just becuase the database CAN do it, doesn't mean it is a good idea to let it.  For example, if you start a transaction, get data, wait for the user to edit the data, the rows (and potentially pages, extents, and ultimately the table) in which you retrieved are now LOCKED..meaning others cannot modify it.  In terms of concurrency, this is a nightmare.  The last thing you want to do is to allow a user to determine how long something is locked at the database level.  Adding a little extra code ensures that you're saving yourself from these headaches.
0
 
NargzulAuthor Commented:
And if we flag the row, she is locked too.

And this isn't an option, the client asked exactly the comportment you describe.
0
 
RiteshShahCommented:
but in that case, you will have control to unlock it, not client. you can change the flag by datetime stamp checking.
0
 
chapmandewCommented:
Well, I would tell the client it is a bad idea....that you can do it, but you advise against it.
0
 
NargzulAuthor Commented:
The database has timeout too ;)
0
 
chapmandewCommented:
of course it does...most queries are going to timeout once you start opening connections and rely on the user to commit them.
0
 
NargzulAuthor Commented:
So why use a logical timeout and not a database timeout?
0
 
chapmandewCommented:
Doing it logically through code, you're not going to get the errors and the locking that is going to come with trying to enforce through the database engine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now