Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I have created a PBIX that used direct query to SQL Azure DB. I initially created this report in development environment that points to my development DB.
For production purpose, I programatically upload this report to a group in Power BI. Likewise for other reports. Then I try to programatically update the data source along with credentials using PowerBI API. But it fails. It updates the data source (DB server and catalog), but not the credentials.
Below is my sample code that updates the data source connection string:
foreach( var ds in client.Datasets.GetDatasetsInGroup(grp.Id).Value)
client.Datasets.SetAllDatasetConnectionsInGroup(grp.Id,ds.Id , new ConnectionDetails(ConnectionString));
Am I doing it the right way. Kindly advice.
@shiva wrote:
I have created a PBIX that used direct query to SQL Azure DB. I initially created this report in development environment that points to my development DB.
For production purpose, I programatically upload this report to a group in Power BI. Likewise for other reports. Then I try to programatically update the data source along with credentials using PowerBI API. But it fails. It updates the data source (DB server and catalog), but not the credentials.
Below is my sample code that updates the data source connection string:
foreach( var ds in client.Datasets.GetDatasetsInGroup(grp.Id).Value)
client.Datasets.SetAllDatasetConnectionsInGroup(grp.Id,ds.Id , new ConnectionDetails(ConnectionString));
Am I doing it the right way. Kindly advice.
You'll have to set credentials after updating the connection string, see Set Credentials, you'll get the gatewayid from Get BoundGatewayDatasources.
Thanks for the reply.
I am not using any gateway. I am using PowerBI with SQL Azure. Why should I create a gateway ?
@shiva wrote:
Thanks for the reply.
I am not using any gateway. I am using PowerBI with SQL Azure. Why should I create a gateway ?
Azure SQL in Power BI internally actually uses gateway, however there's nothing for you to configure. If you call Get BoundGatewayDatasources by passing the Azure SQL datasetid, you'll get the gatewayid.
Hi Eric, kindly refer to the above pic, I am getting forbidden access error. What could be the reason? Below is the code I used:
string uri = string.Format("https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1}", result[0].GatewayId, item.Id);
var Uri = new Uri(uri);
var content = new StringContent("{ \"credentialType\": \"Basic\", \"basicCredentials\": { \"username\": \"userName\", \"password\": \"password\" }}", System.Text.Encoding.Default, "application/json");
using (var request = new HttpRequestMessage { Method = new HttpMethod("PATCH"), RequestUri = Uri, Content = content })
{
var rep = client.HttpClient.SendAsync(request).Result;
}
@shiva wrote:
Hi Eric, kindly refer to the above pic, I am getting forbidden access error. What could be the reason? Below is the code I used:
string uri = string.Format("https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1}", result[0].GatewayId, item.Id);
var Uri = new Uri(uri);
var content = new StringContent("{ \"credentialType\": \"Basic\", \"basicCredentials\": { \"username\": \"userName\", \"password\": \"password\" }}", System.Text.Encoding.Default, "application/json");
using (var request = new HttpRequestMessage { Method = new HttpMethod("PATCH"), RequestUri = Uri, Content = content })
{var rep = client.HttpClient.SendAsync(request).Result;
}
try{
//your code here
}
catch (HttpOperationException ex)
{
//Bad Request
var content = ex.Response.Content;
Console.WriteLine(content);
}
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |