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?
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
OUTPUTclause instead though to avoid the possibility of encountering this bug inScope_Identity.