?
Solved

Make a transaction between to pages.

Posted on 2009-05-01
12
Medium Priority
?
249 Views
Last Modified: 2013-11-11
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
Comment
Question by:Nargzul
  • 5
  • 5
  • 2
12 Comments
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24277775
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
 
LVL 1

Author Comment

by:Nargzul
ID: 24277819
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
 
LVL 60

Accepted Solution

by:
chapmandew earned 1500 total points
ID: 24278354
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 1

Author Comment

by:Nargzul
ID: 24278407
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
 
LVL 60

Expert Comment

by:chapmandew
ID: 24278460
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
 
LVL 1

Author Comment

by:Nargzul
ID: 24278614
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
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24278626
but in that case, you will have control to unlock it, not client. you can change the flag by datetime stamp checking.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24278630
Well, I would tell the client it is a bad idea....that you can do it, but you advise against it.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24278682
The database has timeout too ;)
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24278766
of course it does...most queries are going to timeout once you start opening connections and rely on the user to commit them.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24278783
So why use a logical timeout and not a database timeout?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24278815
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question