• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

LAST_INSERT_ID() with OLEDB and ASP returns 0

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
pattoi
Asked:
pattoi
1 Solution
 
UmeshMySQL Principle Technical Support EngineerCommented:
0
 
pattoiAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
peyoxCommented:
Try to run your script with this query:
var sSql="INSERT INTO Registration (name, email) VALUES ('Me', 'me@mail.com')";
0
 
pattoiAuthor Commented:
I have alread tried this also without any success
0
 
pattoiAuthor Commented:
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
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now