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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
latheesh89
Helper II
Helper II

Unable to update connection string using SetAllConnections API

Dear Techies,

 

I was successfully able to upload PBIX files to PBI Service using Import API. Now, I am trying to update the connection string using SetAllConnections API. The dataset that I am trying to update is using SQL Server as source and DirectQuery mode

 

Below is my query snippet, I am getting 404 bad request error

 

private static void UpdateConnection(string DatasetID)

        {

            string powerBIDatasetsApiUrl =String.Format("https://api.powerbi.com/v1.0/myorg/myorg/datasets/{0}/Default.SetAllConnections",DatasetID);

            HttpWebRequest request = System.Net.WebRequest.Create(powerBIDatasetsApiUrl) asSystem.Net.HttpWebRequest;

            request.KeepAlive = true;

            request.Method = "POST";

            request.ContentLength = 0;

            request.ContentType = "application/json";

 

            //Add token to the request header

            request.Headers.Add("Authorization"String.Format("Bearer {0}", token));

 

            string updateJSON = "{\"connectionString\":\"data source=XXXXX;initial catalog=XXXXX;persist security info=True;encrypt=True;trustservercertificate=False\"}";

           

            //POST web request

            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(updateJSON);

            request.ContentLength = byteArray.Length;

 

            //Write JSON byte[] into a Stream

            using (Stream writer = request.GetRequestStream())

            {

                writer.Write(byteArray, 0, byteArray.Length);

 

                var response = (HttpWebResponse)request.GetResponse(); ----Error at this line

                //Console.WriteLine(string.Format("Dataset {0}", response.StatusCode.ToString()));

                Console.ReadLine();

            }

 

        }

 

 

Am I missing something? Please help

 

Thanks,

Latheesh

3 REPLIES 3
Eric_Zhang
Microsoft Employee
Microsoft Employee

@latheesh89

There'a actually an error in the Set All Connections API which leads to a 404 error. Try to remove the duplicated /myorg from the Url .../myorg/myorg/...

Thanks Eric,

 

I even tried removing myorg, but my error didn't get resolved.


@latheesh89 wrote:

Thanks Eric,

 

I even tried removing myorg, but my error didn't get resolved.


@latheesh89

Where is the dataset in your case? If in some group, you'll specify the groupid in the POST request url. Can you double comfirm that the datasetid is correct?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors