我分配了一个任务,使用来自SQL表的实时数据流来设置实时Power BI在线服务磁贴。表中的数据每隔几秒钟更新一次。这是我到目前为止使用PowerShell所得到的。
但是似乎没有每隔几秒钟刷新一次数据集。我想念什么?
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)