Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Gateway for Cross-Database SQL Query

Is it possible to utilize a cross-database SQL Query in Power BI's Online Service? For example, I have a query that I am importing (NOT using DirectQuery) into a Power BI Desktop File that follows this structure:

 

Select a.*, b.*

FROM Server1.Database1.Table1 a

INNER JOIN Server1.Database2.Table2 b on b.id = a.id

 

It is merging data from two different databases within the same SQL Server. When importing the query into Power BI Desktop I have to explicitly list the Server and Database as Server1 and Database1, respectively. The refresh works fine in the Desktop version but when I upload to the Online Service and attempt to set-up a refresh schedule I receive an error because the Gateway connection pointing to Database1 cannot access Database2 under the current security context. I receive the "Unable to connect to the data source undefined" error (Class: 14, Number: 916 - DataSource Error).

Therefore, I was wondering if it is possible to create a gateway connection for a SQL Query that accesses multiple databases within the same server? Or is there a Gateway setting that would allow this to happen? I would assume there are multiple case scenarios of Users importing cross-database queries into Power BI's online service. Has anyone else had this issue/come up with a solution?

I do not want to create two data source connections pointing to each table individually and merging in the BI User Interface as they are both very large fact tables (Also connects to multiple dimensional tables). Would I require a SQL View that accesses both tables or would the issue still persist?

 

Any help is appreciated!

3 REPLIES 3
GilbertQ
Super User
Super User

Hi there

What I have done is to use all SQL queries with one datasource in Power BI Desktop.

If I need to do a cross-database query I would do the following:

DataSource Database = MyDB1.dbo.tb_TableName

Query to another database would be:
MyDB2.dbo.tb_OtherTableName

That works well for me.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

I am looking for a way to merge the queries before loading into Power BI (Please see last paragraph of question). Otherwise the analysis would take ages given the vast quantity of records in both respective databases/tables being accessed.

You could achieve it with a view, which would then present itself as coming from a single data source?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors