Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LAST_INSERT_ID() with OLEDB and ASP returns 0

Posted on 2004-09-19
8
Medium Priority
?
774 Views
Last Modified: 2008-02-01
I am trying to retrieve the auto increment ID of a record inserted into a MySQL table.  I am using the MyOLEDB 3 driver with ADO in ASP (JScript).  The INSERT statement is successful but a subsequent call to execute SELECT LAST_INSERT_ID() always returns 0.  My code (simplified) is below:

var sSql="INSERT INTO Registration (RegistrationID, name, email) VALUES (NULL, 'Me', 'me@mail.com')";
oConn.Open(sConn);
oConn.Execute(sSql);
sSql="SELECT LAST_INSERT_ID()";
var iRegID=oConn.Execute(sSql).Fields(0).Value;

0
Comment
Question by:pattoi
8 Comments
 
LVL 6

Expert Comment

by:peyox
ID: 12099191
0
 
LVL 26

Expert Comment

by:Umesh
ID: 12099194
0
 

Author Comment

by:pattoi
ID: 12099359
I have alread looked at both of these articles today and neither of them addresses my problem.  The Experts Exchange item is about a problem that the ID returned is from a different table whereas I am getting 0.  I tried that solution anyway and still get 0.  I also tried the solution from the 4 Guys from Rolla article but I get an error trying to execute the 2 commands separated by a semi-colon.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 6

Expert Comment

by:peyox
ID: 12099397
Try to run your script with this query:
var sSql="INSERT INTO Registration (name, email) VALUES ('Me', 'me@mail.com')";
0
 

Author Comment

by:pattoi
ID: 12099409
I have alread tried this also without any success
0
 

Author Comment

by:pattoi
ID: 12119959
I tried the same code using the MyODBC Driver instead and it works fine so obviously the problem is with MyOLEDB.  That's enough of a solution for me now.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13738752
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question