I would like to use the SELECT LAST_INSERT_ID() statement i MySQL to get the last auto-incremented id.
The documentation says: the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client.
My Questions is what is considered a connection.... each time my web sever connects to the mysql sever it's considerd a different connection correct?
I't's a different connection even if it comes from the same web server? Even if in Asp.net the connection has the same name?
i.e ( Dim myConnection2 As New MySqlConnection(connectionString2))
Will different instances of the above connection example be considered as different connections by MySQL?
If different sessions of my web application are all connecting to the MySQL db with the above connection definition each session will be considered as seperate connection by MySQL?
What I'm concerned about is if somehow my different web sessions use the same connection and therefore it would break the logic of the
SELECT LAST_INSERT_ID() and one user would fetch another one's ID...
Regards,
Andy
"Energy and persistence conquer all things"
- Benjamin Franklin
Andy22
Member
231 Points
93 Posts
LAST_INSERT_ID() on which Connection?
Feb 26, 2012 04:05 PM|LINK
Hi Folks,
I would like to use the SELECT LAST_INSERT_ID() statement i MySQL to get the last auto-incremented id.
The documentation says: the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client.
My Questions is what is considered a connection.... each time my web sever connects to the mysql sever it's considerd a different connection correct?
I't's a different connection even if it comes from the same web server? Even if in Asp.net the connection has the same name?
i.e ( Dim myConnection2 As New MySqlConnection(connectionString2))
Will different instances of the above connection example be considered as different connections by MySQL?
If different sessions of my web application are all connecting to the MySQL db with the above connection definition each session will be considered as seperate connection by MySQL?
What I'm concerned about is if somehow my different web sessions use the same connection and therefore it would break the logic of the SELECT LAST_INSERT_ID() and one user would fetch another one's ID...
Regards,
Andy
- Benjamin Franklin
Please mark as anwser if my post helped you!
Mikesdotnett...
All-Star
154955 Points
19872 Posts
Moderator
MVP
Re: LAST_INSERT_ID() on which Connection?
Feb 26, 2012 07:30 PM|LINK
Correct.
Yes. Can't happen.Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter