472,354 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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
ObjectDataSource. 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.InputParameters.Item("ts") = DetailsView1.DataKey.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 1966

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 "OriginalThis" and "OriginalThat" 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*******@discussions.microsoft.comwrote in message
news:95**********************************@microsof t.com...
(If I'm overlooking anything, please let me know.)

First, my only concern is updating single records in a Detailsview using
an
ObjectDataSource. 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.InputParameters.Item("ts") =
DetailsView1.DataKey.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
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...
8
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...
2
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...
9
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...
2
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...
0
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...
4
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...
1
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...
8
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.