Multiple Threads inserting - Issues using "SELECT @@IDENTITY"

Aug 2, 2013 at 6:52 PM
Hi Chris,

I have multiple thread inserting a lot of records at the same time.

I think the problem results from using @@Identity to get the id.

Id of MdSetupDataObjectValue set to 58075
Id of MdSetup set to 3341
Id of MdSetupDataObjectValue set to 58076
Id of MdSetupDataObjectValue set to 58077
Id of MdSetupDataObjectValue set to 58078
Id of MdSetupDataObjectValue set to 58079
Id of MdSetupDataObjectValue set to 58080
Id of MdSetupDataObjectValue set to 58081
Id of MdSetupDataObjectValue set to 58082
Id of MdSetupDataObjectValue set to 58083
Id of MdSetupDataObjectValueChange set to 339
Id of MdSetupDataObjectValueChange set to 340
Id of LiteEvent set to 343
Id of LiteEvent set to 344
Id of MdSetup set to 344

The above is from the output window, I'm printing the table and Id read back.

Note the last 2 lines... they both read the same ID.

Looks like the other thread A inserted a row and before it had time to read the id thread B inserted a record too.

Any thoughts on ways around that, short of locking access to the "DataStore" object?

Thanks!