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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ashaikh
Helper III
Helper III

Real Stream Dataset for AZURE SQL Server Database Query Using Powershell

Hello,

I am trying Real Stream Dataset reports using powershell. But my SQL Server Database is hosted in Azure. How would I connect it to azure SQL Database using powershell.

 

I have query to do it using local database but I am unable to connect it to AZURE SQL Database using same script.

$SqlServer = 'MySQLserverName';
$SqlDatabase = 'MyDatabaseName';
$user = "MyUsername";
$pwd = "MyPassword $connectionString = “Server=$SqlServer;uid=$user; pwd=$pwd;Database=$SqlDatabase;Integrated Security=False;” $SqlQuery = "SELECT * FROM table;"; $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 = "myEndPoint" #Fetch data and write out to files while ($SqlDataReader.Read()) { $payload = @{ "product" =$SqlDataReader['product'] "sales" =$SqlDataReader['sales'] "datetime" =$SqlDataReader['datetime'] } Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload)) } $SqlConnection.Close(); $SqlConnection.Dispose();

I also have a script to connect to Azure Database using Powershell. This is how I connect -

 

$params = @{

  'Database' = 'MyDatabase'

  'ServerInstance' =  'MyServerName'

  'Username' = 'MyUsername'

  'Password' = 'MyPassword'

  'OutputSqlErrors' = $true

  'Query' = 'SELECT * FROM table'

  }

$result = Invoke-Sqlcmd @params
1 REPLY 1
v-yuta-msft
Community Support
Community Support

@ashaikh,

 

This issue is more related to azure sql server, pleae refer to: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-powershell-samples.

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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