views:

17

answers:

1

As part of a transaction I’m modifying rows in tables via a server link, so have to specify “SET XACT_ABORT ON” in my sproc otherwise it won’t execute. Now I’m noticing that SCOPE_IDENTITY() is returning NULL, which is presumably something to do with the distributed transaction scope?

Does anyone know why and how to resolve?

+1  A: 

From @@IDENTITY:

The scope of the @@IDENTITY function is current session on the local server on which it is executed. This function cannot be applied to remote or linked servers. To obtain an identity value on a different server, execute a stored procedure on that remote or linked server and have that stored procedure (which is executing in the context of the remote or linked server) gather the identity value and return it to the calling connection on the local server.

And note that although it talks about IDENT_CURRENT and SCOPE_IDENTITY in surrounding paragraphs, they make no appearance in this paragraph; i.e. none of them will work to retrieve identity values from remote servers.

Damien_The_Unbeliever