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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
janfcarl
Helper I
Helper I

How to update data sources of datasets programmatically

Hi, I am trying to update data sources of datasets in a workspace, with API v2. I use C#.

My code is

 

powerBIClient.Datasets.SetAllDatasetConnectionsInGroup(workspaceId, datasetId, new ConnectionDetails(connectionString));

 

Unfortunately, this causes a "Bad request" error. Instead of this, I used

 

var dataSources = powerBIClient.Datasets.GetDatasourcesInGroup(workspaceId, datasetId).Value.ToList();
foreach (var dataSource in dataSources)
{
     dataSource.ConnectionString = connectionString;
}

 

Is this the correct way of doing it?

1 ACCEPTED SOLUTION

The link of that request recommends using this Update Datasources in Group:
https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/update-datasources-in-group

Please read the limitations in the post to be sure you can do what you are looking for.

I hope that helps


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

3 REPLIES 3
ibarrau
Super User
Super User

Hi. Bad request is usually about having a wrong url or parameters. In your case using the C# library will help you always getting the correct url. However, if you have already try some requests and are working, you should take a look at the documentation of the API.

I have just read that the Set All Dataset Connections In Group is deprecated and no longer supported 😞

https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/set-all-dataset-connections-in-group

I don't think you can do that any more. It suggests using Update Datasources In Group. You can try that one.

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Thanks, that is helpful. Could you give me the exact api operation to update datasources in the api?

The link of that request recommends using this Update Datasources in Group:
https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/update-datasources-in-group

Please read the limitations in the post to be sure you can do what you are looking for.

I hope that helps


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors