Hello,
I am using Delphi 10.2.2, UniDAC 7.1.3, SQL Server 2012, SQL Server 2016 and PostgreSQL 10.1
My application can use SQL Server and PostgreSQL databases depending on user choice. Databases can be switched to another if user would like so. All connection parameters as well as some SpecificOptions are saved and loaded when application is starting.
That application at some point runs some operations in Thread. We know that each Thread require its own TUniConnection for safe operation.
My question is:
Is there a ready function/method to copy my already connected Main Application TUniConnection properties into Thread TUniConnection properties?
Please note that I do need almost identical DataModule.UniConection1 and MyThread.UniConnection1. Meaning all parameters, Options and SpecificOptions to be copied except MyThread.UniConnection1 will not be connected to database until I tell it to do so.
I am hesitating to call all these procedures for MyThread.UniConnection1 parameters to be loaded again and again from file system for each thread use.
I can implement my own copy procedure, however, I would like to learn if there is already something available.
Thanks & regards,
Ertan
Copy one TUniConnection to another TUniConnection
Re: Copy one TUniConnection to another TUniConnection
I couldn't find anything that worked for me so here is what I added:
Once the main Connection is connected your ConnectString will/should contain all relevant info, including those loaded from SpecificOptions.
But that wasn't enough, dealing with multiple dbs required the Macros to be available as well.
Code: Select all
function TUniConnection.CloneConnection(Owner: TComponent = nil): TUniConnection;
begin
if not Connected then raise Exception.Create('Cannot clone a connection without being connected.');
Result := TUniConnection.Create(Owner);
Result.ConnectString := ConnectString;
Result.Macros.Assign(Macros);
end;
But that wasn't enough, dealing with multiple dbs required the Macros to be available as well.
Re: Copy one TUniConnection to another TUniConnection
In UniDAC, there is no separate functionality for copying TUniConnection properties and SpecificOptions for all providers from one instance to another. You can implement this functionality by yourself.
Re: Copy one TUniConnection to another TUniConnection
Thank you for sharing. As my license do not include source codes, I am not able to directly use your suggestion. However, I can still implement something similar out of it.FredS wrote:I couldn't find anything that worked for me so here is what I added
Re: Copy one TUniConnection to another TUniConnection
A Class Helper would work just as well.ertank wrote:FredS wrote:I am not able to directly use your suggestion. However, I can still implement something similar out of it.