Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:48:25+00:00 2026-05-15T20:48:25+00:00

I have derived my own component from TAdoQuery in Delphi. I have overridden the

  • 0

I have derived my own component from TAdoQuery in Delphi. I have overridden the DoAfterPost procedure; and in this code I create another query for the purpose of fetching the primary key associated with an inserted record (i.e. SELECT @@IDENTITY for SqlServer, SELECT LAST_INSERT_ID() for MySql, etc).

In the past I always used TAdoConnection for database connectivity. And in the “subquery” call made within DoAfterPost there was no problem because it was the SAME Session (these queries to retrieve last inserted primary keys assume a persistent database connection).

I recently made an option where instead of using a TAdoConnection connection, I am instead setting the ConnectionString property (for multi-thrading purposes). But this creates a problem because the spawned subquery does not use the same session as the main query. Hence it does not return the primary key value.

My question is, does TAdoQuery have any Connection property if the ConnectionString is used? I could then daisychain this connection/session to my subquery. Or is the only way to accomplish this via a TAdoConnection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:48:26+00:00Added an answer on May 15, 2026 at 8:48 pm

    @M Schenkel, when you set the ConnectionString property of the TADOQuery component, the TAdoQuery create a new connection to the database with a new session id.

    the @@IDENTITY SQL Server function return the last-inserted identity value in the current session , because that you need to use the same Connection (and session) for the insert statement and the query SELECT @@IDENTITY.

    As workaround in sql server you can use the IDENT_CURRENT function wich is not limited to an session.

    In MySql the LAST_INSERT_ID() function also works on a perconnection. therefore the behavior is similar to the function @@IDENTITY.

    In short, the best option you have is to use an unique TAdoConnection object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a derived derived class from an abstract class. The code is below.
I have my own control derived from Windows.Forms.Control and I am checking the Parent.BackColor
We have derived our own Utility String class from RogueWave's RWCString class. Derived class
I have a class derived from ItemsControl in which I implement my own selection-algorithm
I have my own custom element derived from StyledMultilineElement: public class SubmenuElement : StyledMultilineElement
I have derived from a 3rd party class, and when I attempt to call
I have an AST derived from the ANTLR Parser Generator for Java. What I
I have a window (derived from JFrame) and I want to disable the close
I have a class derived from CTreeCtrl . In OnCreate() I replace the default
I made my own class derived by NSObject, and here is my code: -(void)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.