5

Where in the .NET System.Data namespace is the code that determines, when the update-command is executed, whether a row in a SQL Server 2K table has been changed after the client program had read it in, i.e. that the client-side version of the row is "stale"?

I would like to use a decompiler to look at the code and figure out how it determines that a concurrency violation has happened. I know it will have something to do with a timestamp column in the table and/or @@rowcount but I'd like to see just what is going on when an update command wrapped in a stored proc is executed by the library.

The stored proc would have this structure:

               create proc foo_update
                @id int,
                @rowversion timestamp,
                @val varchar(5)
                as
                 begin
                   update foo set a = @val
                   where id = @id and mytimestampcolumn = @rowversion; 
                 end

That is, no row will be updated if it has changed because of the where-clause which compares the rowversion in the client-side System.Data.DataRow to the timestamp value of the row in the database, and the proc would run successfully and not generate an error. Yet the SqlClient libraries, in their helpfulness, report this scenario as a concurrency violation.

Thanks

Tim
  • 8,669
  • 31
  • 105
  • 183
  • Are you using a `SqlDataAdapter`? How are you calling it? What do you want to achieve by finding this source code, bypass the concurrency violation error? – Jordão Apr 08 '12 at 20:10
  • @Jordão: I wanted to see what conditions were necessary for the error to be thrown, that is, whether the library was comparing the timestamp values, or simply looking at the number of records affected. – Tim Apr 10 '12 at 18:42

2 Answers2

2

Instead of using decompiler, look to real code. see following blog post for details. http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • @Attila Ozgur: Thanks for the help. Having the actual source code to search through led me eventually to the answer. I see the SO website awarded you 50% of the bounty automatically. – Tim Apr 16 '12 at 18:08
0

I found the relevant code in System.Data.Common.DbDataAdapter.cs -- the concurrency violation is raised when the number of affected records is zero.

Tim
  • 8,669
  • 31
  • 105
  • 183