title: Livestream data from SQL to Power BI online service using PowerShell or other options
body: <p>I have an assignment to setup a live Power BI online service tile using live data streaming from SQL table. The data in the table updates every few seconds. Here is what I got so far using PowerShell.</p>
  
  <p>But it appears to be not refreshing the data set every few seconds. What am I missing?</p>
  
  <pre><code>DO
          {   
          $SqlServer = 'ServerName';
          $SqlDatabase = 'DBName';
          $sleepDuration = 3
          $SqlConnectionString = 'Data Source={0};Initial Catalog={1};Integrated Security=SSPI' -f $SqlServer, $SqlDatabase;
          $SqlQuery = "SELECT * FROM MyTable;";
  
          $SqlCommand = New-Object -TypeName System.Data.SqlClient.SqlCommand;
          $SqlCommand.CommandText = $SqlQuery;
          $SqlConnection = New-Object -TypeName System.Data.SqlClient.SqlConnection -ArgumentList $SqlConnectionString;
          $SqlCommand.Connection = $SqlConnection;
  
          $SqlConnection.Open();
          $SqlDataReader = $SqlCommand.ExecuteReader();
  
          ##you would find your own endpoint in the Power BI service
          $endpoint = "......My PowerBI Service Push URL.........."
  
  
  
          #Fetch data and write out to files
          while ($SqlDataReader.Read()) {
               $payload =  
              @{
              "Col1" =$SqlDataReader['Col1']
              "Col2" =$SqlDataReader['Col2']
  
                  } 
              Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
           # Sleep for a second
              Start-Sleep $sleepDuration
          }
          $SqlConnection.Close();
          $SqlConnection.Dispose();
  
          } While (1 -eq 1)
  </code></pre>