473,585 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optimistic concurrency. I've found a ridiculously easy method.

(If I'm overlooking anything, please let me know.)

First, my only concern is updating single records in a Detailsview using an
ObjectDataSourc e. The target table has a timestamp field. Assume a single
primary key.

Create your xsd. Drag the table onto the xsd. Then manually edit the
Update statement to simplify it. Essentially 'Update <tableset blah = blah
Where (PK=@PK) and (ts=@ts)'. (Get rid of all that auto-generated 'original'
stuff. Also those IsNulls. They don't seem to serve any purpose except to
confuse. Don't use the Optimistic Concurrency option in the wizard.)

Get the record into the detailsview any way you see fit. I generally use
the first select statement to populate a grid and then call the detailsview
through a hyperlink. Then I create a 2nd select by PK.

Bind your detailsview. Here's the critical step. Add the timestamp field
to the DataKeyNames property of the detailsview (since the timestamp datatype
can't be passed any other way apparently.)

Next, add the following code to the Object Data Source Updating event
handler: e.InputParamete rs.Item("ts") = DetailsView1.Da taKey.Item(1)

That's it. The only other thing you really have to do is check the
e.ReturnValue in the Object Data Source Updated. 1 is success, 0 is failure.
(For some reason the AffectedRows parameter is always returning -1)

Apparently if you use this sort of method, you are responsible for reporting
success or failure on the webpage. (Actually I was expecting a crash when I
tried to update an already updated record, but so much the better.)

One last question: Why have I not seen this in any tutorial?
Dec 18 '07 #1
1 2046

I think you've got a good tutorial, but I don't think you've discovered
anything new.

http://www.google.com/search?hl=en&q...2sql+server%22

http://davidhayden.com/blog/dave/arc...0/05/2503.aspx
Optimistic Concurrency Strategies
If you are in a performance state-of-mind, chances are you will go with
optimistic concurrency. Optimistic concurrency frees up database resources
as quickly as possible so that other users and processes can act upon that
data as soon as possible.

To the best of my knowledge, there are four popular strategies to dealing
with optimistic concurrency:

1.. Do Nothing.
2.. Check for changes to all fields during update.
3.. Check for changes to modified fields during update.
4.. Check for changes to timestamp ( rowversion ) during update.
I agree the N number of "OriginalTh is" and "OriginalTh at" is a pain is
overkill and ugly and non maintainable.

...

Start a blog, post your tutorial...then others can learn from your example.
Windows Live has free blog space.
http://sholliday.spaces.live.com/blog/

"B. Chernick" <BC*******@disc ussions.microso ft.comwrote in message
news:95******** *************** ***********@mic rosoft.com...
(If I'm overlooking anything, please let me know.)

First, my only concern is updating single records in a Detailsview using
an
ObjectDataSourc e. The target table has a timestamp field. Assume a
single
primary key.

Create your xsd. Drag the table onto the xsd. Then manually edit the
Update statement to simplify it. Essentially 'Update <tableset blah =
blah
Where (PK=@PK) and (ts=@ts)'. (Get rid of all that auto-generated
'original'
stuff. Also those IsNulls. They don't seem to serve any purpose except
to
confuse. Don't use the Optimistic Concurrency option in the wizard.)

Get the record into the detailsview any way you see fit. I generally use
the first select statement to populate a grid and then call the
detailsview
through a hyperlink. Then I create a 2nd select by PK.

Bind your detailsview. Here's the critical step. Add the timestamp field
to the DataKeyNames property of the detailsview (since the timestamp
datatype
can't be passed any other way apparently.)

Next, add the following code to the Object Data Source Updating event
handler: e.InputParamete rs.Item("ts") =
DetailsView1.Da taKey.Item(1)

That's it. The only other thing you really have to do is check the
e.ReturnValue in the Object Data Source Updated. 1 is success, 0 is
failure.
(For some reason the AffectedRows parameter is always returning -1)

Apparently if you use this sort of method, you are responsible for
reporting
success or failure on the webpage. (Actually I was expecting a crash when
I
tried to update an already updated record, but so much the better.)

One last question: Why have I not seen this in any tutorial?

Dec 18 '07 #2

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

Similar topics

1
3177
by: Chris Huddle | last post by:
Is there a way to turn off optimistic concurrency in ASP.NET when updating a record via the oleDBdataAdapter/oleDBcommandBuilder? If you use the Microsoft ASP.NET tools you can turn it off and thus modify the SQL statement so that it doesn't include the WHERE portion, but I'm not sure how to do the same thing in the code. I do my...
8
5026
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for...
2
2188
by: John | last post by:
In 'Data Adapter Configuration Wizard' for OleDbDataAdapter, there's a checkbox called 'Use optimistic concurrency' that allows to turn on/off the option. I don't use the wizard, I create MyDataAdapter using the following, MyDataAdapter = new New OleDbDataAdapter(MySql, MyDatabase) The question is how to turn off the 'Use optimistic...
9
2022
by: corey.coughlin | last post by:
Alright, so I've been following some of the arguments about enhancing parallelism in python, and I've kind of been struck by how hard things still are. It seems like what we really need is a more pythonic approach. One thing I've been seeing suggested a lot lately is that running jobs in separate processes, to make it easy to use the latest...
2
1584
by: stuart.d.jones | last post by:
Hi, I'm using a detailsview control with an SqlDataSource control. My Update query isn't working, and I've narrowed it down to the optimistic concurrency parameters - i.e. when I comment them out of the query, it works. What seems to be happening is that if a field is NULL when it is read in through the select statement, it's causing the...
0
1560
by: russganz | last post by:
It seems to me there are real problems with the datagridview (along with the detailsview and form view) control when using optimistic concurrency with fields that can be null. Trying to use these controls I have many times had the update not work with no error generated. After much experimentation I have narrowed it down to how the Update...
4
1572
by: Andrew Robinson | last post by:
I am working on a system system that requires optimistic concurrency within a web app. At first I thought this would be easy. We generate our own entities and dal/service layer but I now see that working with controls like a grid view pose some very complicated issues. If I am using rowversion, when do I start the "clock"? When I first...
1
1190
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I was suddenly told to whip up a web project in ASP.Net 2.0. The last few weeks have been a crash course in new technology. I've done some 1.1 web work but it's been a while. The basics are really quite simple and I want to keep it that way. I'm using virtually nothing but grid views and detailsviews. The grids are used solely for display....
8
3967
by: Roger.Noreply | last post by:
Hi, Sql-Server 2000, 2005. A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the sql is generated on the fly by a tool and not easily changeable). SELECT col1, col2 FROM mytab WITH (ROWLOCK) WHERE ...." The select-clause runs for several minutes. Another user fetches one of those rows and tries to update it. The result...
0
8195
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7947
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6596
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5386
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2340
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 we have to send another system
0
1171
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.