delphi - Using ConnectionString instead of TAdoConnection on a TAdoQuery -


I have received my own component in Delphi from TAdoQuery. I override the DoAfterPost process Have given; And in this code I have a primary key associated with a recorded record (i.e. SELECT @@ IDENTITY for SqlServer, SELECT LAST_INSERT_ID () for the purpose of bringing it to MySQL And create queries, etc.).

In the past, I have always used TAdoConnection for database connectivity and there was no problem in the "subquery" call made within DoAfterPost because it was the only session < / Strong> (these questions continually consider the database connection to recover the last entered primary key).

I have recently made a choice where instead of using a TAdoConnection connection, I instead use ConnectionString property (multi-threading purposes ) I am establishing But this creates a problem because the sponsored subkey does not use sessions similar to the main session. So it does not return the primary key value.

My question is, is there any connection property in Tidoclue if connection string is used? Then I could do this connection / session in my subcube: Desicain . Or is it the only way to complete through a TAdoConnection?

@M Scakeel, when you set the property component, TAdoQuery database with a new session ID

Returns the last inserted identity value in the SQL Server function Current Sessions , because you use the same connection (and session) for the contained statement and query Need to do SELECT @@ IDENTITY .

As a workaround in SQL Server, you can use the function that is not restricted to a session.

The function in MySQL also works on the connection. Therefore the behavior is similar to @@ IDENTITY .

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


Comments