SCOPE_IDENTITY() trick in OnAfterUpdateRecord not working

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
dmajkic
Posts: 5
Joined: Thu 01 May 2008 11:20

SCOPE_IDENTITY() trick in OnAfterUpdateRecord not working

Post by dmajkic » Tue 14 Jul 2009 12:00

Hi.

I was using SCOPE_IDENTITY() trick in OnAfterUpdateRecord of TProvider, but it is not working any more since SELECT SCOPE_IDENTITY() called from event is executed in another scope.

Using DBMonitor, I can see that INSERT INTO (...) is executed via one Cursor and SELECT SCOPE_IDENTITY() via another cursor which is other scope, and i allways get NULL as result.

SELECT @@IDENTITY retreives a value, but it is wrong one if table has triggers which update another table (and that is the main reason why SCOPE_IDENTITY use is advised over @@IDENTITY).

Any help on how to retreive correct IDs after inserting into table?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 20 Jul 2009 12:06

Please. try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

Post Reply