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

Update connection string for Imported PBIX file

Dear Techies,

 

I have to import PBIX files to multiple workspaces. Each workspace is meant to point diffrent Analysis Services DB and we have on premises gateway for this instance. The Problem is when I try to Import PBIX files using Import API. Connection string is set same across all the workspaces. Which should not be the case, PBIX file should point to its respective Analysis Services DB in a workspace.

 

I am trying to use SetAllConnections API to update the connection string. But I am getting 400 bad request exception, please refer my code below

 

Am I missing anything here? I don't have much coding knowledge please help me out

 

private static void UpdateConnection(string DatasetID)

        {

            string powerBIDatasetsApiUrl = String.Format(" https://api.PowerBI.com/v1.0/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=DEVXXXX;initial catalog=XXX;Cube=Occupancy;persist security info=False\",\"ConnectionType\":\"analysisServicesDatabaseLive\"}";

 

            //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();

                Console.ReadLine();

            }

 

        }

 

Please post the sample code 

 

Thanks in Advance,

Latheesh

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee

@latheesh89

I don't think you can call the API for a dataset connecting to Analysis Service. Per my test, that API only works for dataset in direct query mode, anyhow live connction for AS is not treated as direct query mode.

 

For quick testing purpose, you can reference this thread.

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.