Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Canale
Regular Visitor

Query from powershell to SQL

Hello

My problem is next:

 

I need make a query to read a database from powershell to sqlserver and after that up to powerbi online

any ideas about that.

 

this is my code

 

$SQLServer = "server"
$SQLDBName = "prueba"
$uid ="remoto"
$pwd = " "
$query = "SELECT * FROM table WHERE Column = 'id'"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True; User ID = $uid; Password = $pwd;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet

 $endpoint = "https://api.powerbi.com/beta/1b682faf-ba6c-46c6-a1e7-74ebc6a55b1f/datasets/8cb9acd2-13a8-486d-93bc-1..."


$payload = @{
"FC210-2" =  "This put de value  I call from sql"
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Canale,

 

You may refer to the following post.

https://community.powerbi.com/t5/Developer/Stream-Dataset-for-local-SQL-Server-Database-Query/td-p/1...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Canale,

 

You may refer to the following post.

https://community.powerbi.com/t5/Developer/Stream-Dataset-for-local-SQL-Server-Database-Query/td-p/1...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Canale
Regular Visitor

Hello

My problem is next:

 

I need make a query to read a database from powershell to sqlserver and after that up to powerbi online

any ideas about that.

 

this is my code

 

$SQLServer = "server"
$SQLDBName = "prueba"
$uid ="remoto"
$pwd = " "
$query = "SELECT * FROM datos WHERE Column = 'id'"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True; User ID = $uid; Password = $pwd;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet

 $endpoint = "https://api.powerbi.com/beta/1b682faf-ba6c-46c6-a1e7-74ebc6a55b1f/datasets/8cb9acd2-13a8-486d-93bc-1..."


$payload = @{
"FC210-2" =  "This put de value from sql"
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.