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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rmiranti
Frequent Visitor

REST API Identification of Import vs Direct Query Datasets

I am using the C# SDK and the REST API to do a lot programmatically with a large number of reports, created in Power BI Desktop and connected to databases through either Direct Query or Import Mode.  Since there is different functionality between these two modes, I want to be able to identify whether a particular dataset is Direct Query or Import.  So far my only way to detect this is to attempt a method that works with Direct Query and, if it throws an exception("Invalid dataset" or "Bad Request"), try the method for Import mode.  That should not be the best way to determine the dataset mode, but I'm not sure how else to do it.  Are there any good ways to identify the difference between Direct Query and Import datasets without relying on exceptions?

1 ACCEPTED SOLUTION

The Set All Connections call is the one I've been using, since I need to change connection strings (but this will currently only work for DirectQuery datasets).  In seeking other options, I found that Get Datasources yields the same result: a status code "BadRequest" with the message "Invalid dataset. This API can only be called on a DirectQuery dataset."  So it appears that checking for this response from one of those calls is the only way to identify which mode is used?

View solution in original post

3 REPLIES 3
Eric_Zhang
Microsoft Employee
Microsoft Employee


@rmiranti wrote:

I am using the C# SDK and the REST API to do a lot programmatically with a large number of reports, created in Power BI Desktop and connected to databases through either Direct Query or Import Mode.  Since there is different functionality between these two modes, I want to be able to identify whether a particular dataset is Direct Query or Import.  So far my only way to detect this is to attempt a method that works with Direct Query and, if it throws an exception("Invalid dataset" or "Bad Request"), try the method for Import mode.  That should not be the best way to determine the dataset mode, but I'm not sure how else to do it.  Are there any good ways to identify the difference between Direct Query and Import datasets without relying on exceptions?


@rmiranti

AFAIK, there's no more elegant way  to find out dataset in DQ or Import mode than the "method" you mentioned.

By the way, is the method calling the Get Datasources REST API?

The Set All Connections call is the one I've been using, since I need to change connection strings (but this will currently only work for DirectQuery datasets).  In seeking other options, I found that Get Datasources yields the same result: a status code "BadRequest" with the message "Invalid dataset. This API can only be called on a DirectQuery dataset."  So it appears that checking for this response from one of those calls is the only way to identify which mode is used?

Update in case others are looking for this: the Get Datasources call no longer returns a BadRequest, but a datasource with a null Name and ConnectionString, so I've had to adapt my code accordingly.  I'm also wondering if the response might change again in the future, if/when Import dataset connection strings can ever be changed via API.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.