Replies Back to Article

Retrieving Unique ID after Insert with SQL Server 2000

I wonder !!!
March 14, 2002 by nicolas diogo

I have posted some comments on this page before but they seem to be deleted...

What about if you guys start giving some help and reply to our questions.

At the end of the day we are the people that keep coming back.

I had a problem with the extention mentioned here and see that other people as well. It is about an XML file missing.

Do you know how to fix it? Or you are just going to delete this message?

Nicolas

Possible wrong identity returned
March 23, 2002 by Andy Yule

Is it not possible (I think it is) that if two or more users submitted the same insert at similar times that the identity return could be from the another user. Example with two users below, in the order they happen, this problem can manifest itself more frequently when more users are operating the system and/or the same table is being updated by other processes.

1) User 1 - Issues Insert                             

2) User 2 - Issues Insert

3) User 1 - Retrieve Ident

4) User 2 - Retrieve Ident

Maybe a couple of alternatives are :

1) The table definition must have an alternative primary key (that may be a composite key) but is not the identity column, immediately after the insert, issue a select with this key to get the identity column value. If the table has been defined with a unique key then you will always get the correct identity value back.

2) Use a stored procedure that performs the insert and the does a select @@identity all within a transaction.

3) Put option 1 in a SP - I think this would be the most robust.

 

RE: Possible wrong identity returned
March 24, 2002 by George Petrov
No this is not possible because the @@identity value is for set for the current connection only - so it isn't effected by other Inserts from within other connections but the current one.
I get the message
May 8, 2002 by Louis Williams

[Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in string in query expression 'SeekUsername='%'"

Please tell me what is wrong

I am using dreamweaver ultradev: in the insert record insertion form canot be completed if this is not correct

Thank you

lou

RE: I wonder !!!
December 6, 2002 by user user
You must create using ASPVB not ASPJAVA.  That is the cause of the XML error.
GREAT JOB!!!
January 8, 2004 by Mitchel Tendler

What would we do without Richard Davies?

Thanks...you made my life a little easier.

hiya
August 22, 2005 by sdsaddsa asdsadd

hi does this solution work with MySQL because im getting this error

Microsoft OLE DB Provider for ODBC Driverserror '80040e31'

Unknown system variable 'NOCOUNT'

if not is there a way to adjust it so it does or is there a tutorial you could link me to

thanks