ProvisionSample/Program.cs
/// <summary>
/// Updates the Power BI dataset connection info for datasets with direct query connections
/// </summary>
/// <param name="workspaceCollectionName">The Power BI workspace collection name</param>
/// <param name="workspaceId">The Power BI workspace id that contains the dataset</param>
/// <returns></returns>
Updates the Power BI dataset connection info for datasets with direct query connections
Updates the Power BI dataset connection info for datasets with direct query connections
static async Task UpdateConnection(string workspaceCollectionName, string workspaceId)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                Console.Write("Username: ");
                username = Console.ReadLine();
                Console.WriteLine();
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                Console.Write("Password: ");
                password = ConsoleHelper.ReadPassword();
                Console.WriteLine();
            }
            string connectionString = null;
            Console.Write("Connection String (enter to skip): ");
            connectionString = Console.ReadLine();
            Console.WriteLine();
            using (var client = await CreateClient())
            {
                var datasets = await client.Datasets.GetDatasetsAsync(workspaceCollectionName, workspaceId);
                if (!string.IsNullOrWhiteSpace(connectionString))
                {
                    var connectionParameters = new Dictionary<string, object>
                    {
                        { "connectionString", connectionString }
                    };
                    await client.Datasets.SetAllConnectionsAsync(workspaceCollectionName, workspaceId, datasets.Value[datasets.Value.Count - 1].Id, connectionParameters);
                }
                var datasources = await client.Datasets.GetGatewayDatasourcesAsync(workspaceCollectionName, workspaceId, datasets.Value[datasets.Value.Count - 1].Id);
                var delta = new GatewayDatasource
                {
                    CredentialType = "Basic",
                    BasicCredentials = new BasicCredentials
                    {
                        Username = username,
                        Password = password
                    }
                };
                await client.Gateways.PatchDatasourceAsync(workspaceCollectionName, workspaceId, datasources.Value[datasources.Value.Count - 1].GatewayId, datasources.Value[datasources.Value.Count - 1].Id, delta);
            }
        }
static async Task UpdateConnection ( string workspaceCollectionName , string workspaceId ) { if ( string . IsNullOrWhiteSpace ( username ) ) { Console . Write ( " " ) ; username = Console . ReadLine ( ) ; Console . WriteLine ( ) ; } if ( string . IsNullOrWhiteSpace ( password ) ) { Console . Write ( " " ) ; password = ConsoleHelper . ReadPassword ( ) ; Console . WriteLine ( ) ; } string connectionString = null ; Console . Write ( " " ) ; connectionString = Console . ReadLine ( ) ; Console . WriteLine ( ) ; using ( var client = await CreateClient ( ) ) { var datasets = await client . Datasets . GetDatasetsAsync ( workspaceCollectionName , workspaceId ) ; if ( ! string . IsNullOrWhiteSpace ( connectionString ) ) { var connectionParameters = new Dictionary < string , object > { { " " , connectionString } } ; await client . Datasets . SetAllConnectionsAsync ( workspaceCollectionName , workspaceId , datasets . Value [ datasets . Value . Count - 1 ] . Id , connectionParameters ) ; } var datasources = await client . Datasets . GetGatewayDatasourcesAsync ( workspaceCollectionName , workspaceId , datasets . Value [ datasets . Value . Count - 1 ] . Id ) ; var delta = new GatewayDatasource { CredentialType = " " , BasicCredentials = new BasicCredentials { Username = username , Password = password } } ; await client . Gateways . PatchDatasourceAsync ( workspaceCollectionName , workspaceId , datasources . Value [ datasources . Value . Count - 1 ] . GatewayId , datasources . Value [ datasources . Value . Count - 1 ] . Id , delta ) ; } }
Updates the Power BI dataset connection info for datasets with direct query connections
Updates the Power BI dataset connection info for datasets with direct query connections
// Get the newly created dataset from the previous import process // Optionally udpate the connectionstring details if preent // Get the datasources from the dataset // Reset your connection credentials // Update the datasource with the specified credentials
None
workspaceCollectionName
string
The Power BI workspace collection name
The Power BI workspace collection name
workspaceId
string
The Power BI workspace id that contains the dataset
The Power BI workspace id that contains the dataset