admin管理员组文章数量:1356763
I'm using the PowerBIClient API for creating resources in the PowerBI environment. I'm trying to connect my uploaded Symantic Model to a SQL Server (All in Azure)
I have tried to set the Connection on the DataSet with the pbiClient.Datasets.SetAllDatasetConnectionsAsync, but there I'm missing something.
Trying to first create a DataSource: with CreateDatasourceAsync but there also I have a lack on information. I really want to connect based on managed Identity...
Does someone have a working example how to create a datasource the correct way?
For now I have:
public async Task SetDataConnection(Guid groupId, string datasetId, string reportingSqlServer, string reportingSqldatabase)
{
var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);
var request = new UpdateMashupParametersRequest()
{
UpdateDetails = [
new UpdateMashupParameterDetails() { Name = "DatabaseServer", NewValue = reportingSqlServer },
new UpdateMashupParameterDetails() { Name = "DatabaseName", NewValue = reportingSqldatabase }
]
};
await pbiClient.Datasets.UpdateParametersInGroupAsync(groupId, datasetId, request);
await PatchSqlDatasourceCredentials(pbiClient, groupId, datasetId, "xxxx", "xxxx");
}
public async Task PatchSqlDatasourceCredentials(PowerBIClient pbiClient, Guid groupId, string datasetId, string sqlUserName, string sqlUserPassword)
{
var datasources = (await pbiClient.Datasets.GetDatasourcesInGroupAsync(groupId, datasetId)).Value;
// find the target SQL datasource
foreach (var datasource in datasources)
{
if (datasource.DatasourceType.ToLower() == "sql")
{
// get the datasourceId and the gatewayId
var datasourceId = datasource.DatasourceId;
var gatewayId = datasource.GatewayId;
if (gatewayId is null || datasourceId is null)
{
throw new Exception("GatewayId or DatasourceId is null");
}
// Create UpdateDatasourceRequest to update Azure SQL datasource credentials
var req = new UpdateDatasourceRequest
{
CredentialDetails = new CredentialDetails(
new BasicCredentials(sqlUserName, sqlUserPassword),
PrivacyLevel.None,
EncryptedConnection.NotEncrypted)
};
// Execute Patch command to update Azure SQL datasource credentials
await pbiClient.Gateways.UpdateDatasourceAsync(gatewayId.Value, datasourceId.Value, req);
}
}
}
Thanks in advance Bart
本文标签:
版权声明:本文标题:Example code for Connecting from a Symantic Model in a PowerBi Workspace to a DataSource (SQL Server) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743946442a2566494.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论