Jump to content
  • Advertisement
Sign in to follow this  
skillfreak

[web] asp.net and auto_increment insert id

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sooo.... Once upon a time php had this nice function mysql_get_id() then a troll came along and said, hey, use asp.net, it will give you powers beyond your wildest... so the dog dropped his bone, in search of a more powerful bone... (and no, he wasn't looking at a reflection) ........ wow. QUESTION = How do you receive the insert id from the last insert command via asp.net /w mysql db. You could query the db twice, grabbing the select last_insert_id(), but that, as far as i know, is not thread safe. SO. Where is my asp.net mysql_get_id() function, or property or method or var?

Share this post


Link to post
Share on other sites
Advertisement
Moved to web programming. This is not an issue with ASP.NET, it's an issue with MySQL using proprietary interfaces and wrappers to hide how it works. How are you opening your MySQL database: through ADO.NET, or via a MySQL extension.

Share this post


Link to post
Share on other sites
It should be safe to run two queries one of which performs an insert, and the other which queries the last ID.

ADO.NET connections tend to use pooling (in ASPNET anyway) - which could put you in trouble if the connection was returned to the pool and another one picked up for the next query. But if you do it between a connection.Open() and Close(), that should not happen, I hope.

Don't use the same Connection object on multiple pages - create a new one every time (they just pick a connection out of the pool anyway, AFAIK).

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!