RKh
RKh

Reputation: 14161

Will Scope_Identity work in different application sessions?

My ASP.NET application is using SQL Server 2008 backend.

I have a Web Form which is used by many users simultaneously to enter records. When user clicks SAVE button, a stored procedure inserts record to the database. After the successful execution of this stored procedure, I want to pick the recent record ID of this user. That is, if I am inserting records, I want to pick only the ID of the last record entered by me and not of other user.

Will Scope_Identity work in this situation?

Upvotes: 0

Views: 77

Answers (1)

Martin Smith
Martin Smith

Reputation: 453628

You need to call the function from within the stored procedure itself. After it exits the function won't work.

You might want to consider the OUTPUT clause instead though to avoid the possibility of encountering this bug in Scope_Identity.

Upvotes: 3

Related Questions