You are not logged in.
Hi there!
I have the following code:
var
ConnectionProperties: TSQLDBConnectionProperties;
Conn1, Conn2: TSQLDBConnection;
begin
ConnectionProperties := TSQLDBFireDACConnectionProperties.Create(
'MySQL?Server=127.0.0.1;Port=3306',
'db',
'root',
'pass');
Conn1 := ConnectionProperties.ThreadSafeConnection;
Conn2 := ConnectionProperties.NewConnection;
try
Conn1.Connect;
Conn2.Connect;
finally
Conn1.Free;
Conn2.Free;
ConnectionProperties.Free; // ---> ERROR invalid pointer operation because Conn1 was freed before
end;
end;
My question is: why is the memory management of .ThreadSafeConnection and .NewConnection handeled in different ways? Is it a bug or a feature? .ThreadSafeConnection calls internally the .NewConnection.
Thank you!
Best regards,
cc
Offline
Some database driver (OleDb for example) require to free connection resources in the same thread connection was created. So it is unsafe to write Conn1.Free;
If your application use threads you must use threadSafeConnection and on thread terminate call ConnectionProperties.EndCurrentThread to correctly release connection resources
Offline