public static void UpdateSqlDatabaseConnectionString(Guid WorkspaceId, string DatasetId, string Server, string Database)
        {
            var pbiClient = TokenManager.GetPowerBiClient(requiredScopes);

            Datasource targetDatasource = pbiClient.Datasets.GetDatasourcesInGroup(WorkspaceId, DatasetId).Value.First();

            string currentServer   = targetDatasource.ConnectionDetails.Server;
            string currentDatabase = targetDatasource.ConnectionDetails.Database;

            if (Server.ToLower().Equals(currentServer.ToLower()) && Database.ToLower().Equals(currentDatabase.ToLower()))
            {
                Console.WriteLine("New server and database name are the same as the old names");
                return;
            }

            DatasourceConnectionDetails connectionDetails = new DatasourceConnectionDetails {
                Database = Database,
                Server   = Server
            };

            UpdateDatasourceConnectionRequest updateConnRequest =
                new UpdateDatasourceConnectionRequest {
                DatasourceSelector = targetDatasource,
                ConnectionDetails  = connectionDetails
            };

            UpdateDatasourcesRequest updateDatasourcesRequest = new UpdateDatasourcesRequest(updateConnRequest);

            pbiClient.Datasets.UpdateDatasourcesInGroup(WorkspaceId, DatasetId, updateDatasourcesRequest);
        }
 /// <summary>
 /// Updates the dataset datasources using the specified datasource selectors
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='groupId'>
 /// The group id
 /// </param>
 /// <param name='datasetKey'>
 /// </param>
 /// <param name='updateDatasourcesRequest'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> UpdateDatasourcesAsync(this IDatasets operations, string groupId, string datasetKey, UpdateDatasourcesRequest updateDatasourcesRequest, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateDatasourcesInGroupWithHttpMessagesAsync(groupId, datasetKey, updateDatasourcesRequest, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Updates the dataset datasources using the specified datasource selectors
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='groupId'>
 /// The group id
 /// </param>
 /// <param name='datasetKey'>
 /// </param>
 /// <param name='updateDatasourcesRequest'>
 /// </param>
 public static object UpdateDatasources(this IDatasets operations, string groupId, string datasetKey, UpdateDatasourcesRequest updateDatasourcesRequest)
 {
     return(operations.UpdateDatasourcesAsync(groupId, datasetKey, updateDatasourcesRequest).GetAwaiter().GetResult());
 }