public async Task UpdateConnectionInformation()

in appx/Power BI Embedded/powerbi-sample-app/powerbi-sample-app/Reporting/PowerBIReportClient.cs [69:103]


        public async Task UpdateConnectionInformation(IEnumerable<Dataset> datasets, string serverName, string databaseName, string username, string password)
        {
            foreach (var dataset in datasets)
            {
                // Optionally udpate the connectionstring details if preent
                if (!string.IsNullOrWhiteSpace(serverName) && !string.IsNullOrWhiteSpace(databaseName))
                {
                    string connectionString = String.Format("Server=tcp:{0}.database.windows.net;Database={1};Trusted_Connection=False;",
                        serverName,
                        databaseName);
                    var connectionParameters = new Dictionary<string, object>
                    {
                        { "connectionString", connectionString }
                    };
                    await this._client.Datasets.SetAllConnectionsAsync(this._workspaceCollection, this._workspaceId, dataset.Id, connectionParameters);
                }
                // Reset your connection credentials
                var delta = new GatewayDatasource
                {
                    CredentialType = "Basic",
                    BasicCredentials = new BasicCredentials
                    {
                        Username = username,
                        Password = password
                    }
                };
                // Get the datasources from the dataset
                var datasources = await this._client.Datasets.GetGatewayDatasourcesAsync(this._workspaceCollection, this._workspaceId, dataset.Id);
                foreach (var datasource in datasources.Value)
                {
                    // Update the datasource with the specified credentials
                    await this._client.Gateways.PatchDatasourceAsync(this._workspaceCollection, this._workspaceId, datasource.GatewayId, datasource.Id, delta);
                }
            }
        }