Friday, June 30, 2017

.net typed Datasets: finding out what caused congurency exception

typed datasets have a update command, which has a where clause specifing all original values - easily traced by SQL Server profiler:

'UPDATE [mytable] SET [field1] = @field1, [field2] = @field2
WHERE (([PrimaryKey] = @Original_PrimaryKey) 
AND ((@IsNull_field1 = 1 AND [field1] IS NULL) OR ([field1] = @Original_field1))
AND ((@IsNull_field2 = 1 AND [field2] IS NULL) OR ([field2] = @Original_field2))
'@field1=123, @field2='newStringValue',
@IsNull_field1=0, @Original_field1=1,
@IsNull_fiels2=0, @Original_field2='oldStringValue'

now you can compare the value in the database with the Original_Value from the command and find out which values are differnet - they are blocking.

to do this automatically, you have to catch the exception, get the modified records of the dataset you tried to save, read them again in another dataset and compare those two datasets - (original values)


No comments: