Yes, I had to fight the code a bit but I got it working. This code allows me to update creds for connection to Azure SQL as required when doing DirectQuery.
static void UpdateAzureSqlDataSource(string workspaceCollectionName, string workspaceId, string datasetId) { using (var client = CreatePowerBIClient()) { IList<Dataset> datasets = client.Datasets.GetDatasetsAsync(workspaceCollectionName, workspaceId).Result.Value; foreach (Dataset dataset in datasets) { if (dataset.Name == datasetId) { var datasources = client.Datasets.GetGatewayDatasourcesAsync(workspaceCollectionName, workspaceId, dataset.Id).Result; // Reset your connection credentials var delta = new GatewayDatasource { CredentialType = "Basic", BasicCredentials = new BasicCredentials { Username = azureSqlUser, Password = azureSqlPassword } }; // Update the datasource with the specified credentials client.Gateways.PatchDatasourceAsync(workspaceCollectionName, workspaceId, datasources.Value[0].GatewayId, datasources.Value[0].Id, delta).Wait(); } } } }
The complete sample program is up in a GitHub report at this URL: