Ask query from Delphi with UniDAC components in two SQL Server databases on same server

1.6k Views Asked by At

I want to run a query with TUniQuery (UniDAC components) in two SQL Server databases located on the same server. I think two TUniConnections must be linked on the same query component. Is there any other way to get simultaneously data from both databases? Thanks.

2

There are 2 best solutions below

1
On

Just use the full table name: <database>.<schema>.<table>. In the same query you can reference tables from different databases. So, no need for second connection !

2
On

AFAIK, you can't use two TUniConnections on the same query component at the same time.

The proper way to do this is to set up one SQL Server database to know about the other one by making it a linked server. This allows a single SQL SELECT statement to refer to both tables in the current database and tables in a different one, allowing JOINs or UNIONs. It also allows replication, distributed loads, and other benefits if you need them.