locked
SqlDataSource Optimistic Concurrency check box RRS feed

  • Question

  • User1013419587 posted

    Hi there,
    I have question about 'Optimistic Concurrency check box' in SqlDataSource Advance option. Can anyone elaborate more in details what it does.
    Thank's

    Monday, November 28, 2011 10:43 AM

Answers

  • User3866881 posted

    Hi there,
    I have question about 'Optimistic Concurrency check box' in SqlDataSource Advance option. Can anyone elaborate more in details what it does.
    Thank's

    For web applications that only allow users to view data, or for those that include only a single user who can modify data, there's no threat of two concurrent users accidentally overwriting one another's changes. For web applications that allow multiple users to update or delete data, however, there's the potential for one user's modifications to clash with another concurrent user's. Without any concurrency policy in place, when two users are simultaneously editing a single record, the user who commits her changes last will override the changes made by the first.

    For example, imagine that two users, Jisun and Sam, were both visiting a page in our application that allowed visitors to update and delete the products through a GridView control. Both click the Edit button in the GridView around the same time. Jisun changes the product name to "Chai Tea" and clicks the Update button. The net result is an UPDATE statement that is sent to the database, which sets all of the product's updateable fields (even though Jisun only updated one field, ProductName). At this point in time, the database has the values "Chai Tea," the category Beverages, the supplier Exotic Liquids, and so on for this particular product. However, the GridView on Sam's screen still shows the product name in the editable GridView row as "Chai". A few seconds after Jisun's changes have been committed, Sam updates the category to Condiments and clicks Update. This results in an UPDATE statement sent to the database that sets the product name to "Chai," the CategoryID to the corresponding Beverages category ID, and so on. Jisun's changes to the product name have been overwritten.

    For more about this, you can download the free code sample at:

    http://www.asp.net/data-access/tutorials/implementing-optimistic-concurrency-vb

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 29, 2011 8:50 PM

All replies

  • User-1528094326 posted

    It performs a more detailed check against a record before it updates. For example: take this table into consideration

    Customer
    -----------
    ID
    FirstName
    LastName
    Address

    A regular SQL Select Statement would like something like..

    SELECT * FROM Customer WHERE ID = @ID

    Where as a SQL Select statement using Optomistic Concurrency would look like this...

    SELECT * FROM Customer WHERE ID = @ID AND FirstName = @FirstName AND LastName = @LastName AND Address = @Address

    It checks every column in the table.

    Monday, November 28, 2011 10:48 AM
  • User1013419587 posted

    Hi N_EvilScott,

    First of all thank to your replay. But this is Select command. Can you a little elaborate more.

    Monday, November 28, 2011 10:54 AM
  • User-1528094326 posted

    Optimistic concurrency checks all data being passed through the SqlDataSource. In othre words it will check every table column in any CRUD operation.

    The best way to get a handle with it is to create 2 different datasources, one with optimistic concurency and one without. You will notice the difference right away.

    Monday, November 28, 2011 11:12 AM
  • User3866881 posted

    Hi there,
    I have question about 'Optimistic Concurrency check box' in SqlDataSource Advance option. Can anyone elaborate more in details what it does.
    Thank's

    For web applications that only allow users to view data, or for those that include only a single user who can modify data, there's no threat of two concurrent users accidentally overwriting one another's changes. For web applications that allow multiple users to update or delete data, however, there's the potential for one user's modifications to clash with another concurrent user's. Without any concurrency policy in place, when two users are simultaneously editing a single record, the user who commits her changes last will override the changes made by the first.

    For example, imagine that two users, Jisun and Sam, were both visiting a page in our application that allowed visitors to update and delete the products through a GridView control. Both click the Edit button in the GridView around the same time. Jisun changes the product name to "Chai Tea" and clicks the Update button. The net result is an UPDATE statement that is sent to the database, which sets all of the product's updateable fields (even though Jisun only updated one field, ProductName). At this point in time, the database has the values "Chai Tea," the category Beverages, the supplier Exotic Liquids, and so on for this particular product. However, the GridView on Sam's screen still shows the product name in the editable GridView row as "Chai". A few seconds after Jisun's changes have been committed, Sam updates the category to Condiments and clicks Update. This results in an UPDATE statement sent to the database that sets the product name to "Chai," the CategoryID to the corresponding Beverages category ID, and so on. Jisun's changes to the product name have been overwritten.

    For more about this, you can download the free code sample at:

    http://www.asp.net/data-access/tutorials/implementing-optimistic-concurrency-vb

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 29, 2011 8:50 PM
  • User1013419587 posted

    Hi, Decker Dong, And thank to your replay.

    As i understood wothout Optimistic Concurrency, Last change will affect the database. Is it problem in programming?

    Tuesday, November 29, 2011 10:17 PM
  • User3866881 posted

    As i understood wothout Optimistic Concurrency, Last change will affect the database. Is it problem in programming?

    Hello:)

    In order to avoid conflicts, this is a better doing way。

    Best reguards!

    Tuesday, November 29, 2011 11:38 PM
  • User1013419587 posted

    Thanks Decker Dong.

    Wednesday, November 30, 2011 2:56 PM
  • User3866881 posted

    Thanks Decker Dong.

    Don't mention it!and I hope you can also help others if free and welcome you come here again to have a discussion with us!

    Best reguards!

    :)

    Wednesday, November 30, 2011 7:55 PM