Powershell script to connect to azure sql db

Mohammed Sohel 66 Reputation points
2021-10-11T19:16:21.507+00:00

Hey there,

Can anyone please help me to resolve this issue, am trying to connect to SQL DB from powershell.

"Exception calling "Open" with "0" argument(s): "Windows logins are not supported in this version of SQL Server."

Can anyone please help me to rewrite the script,139550-error-db.png

Function get-ResizeData
{

[string] $SQLServer= "ocagautomationdatabasedev.database.windows.net"  

[string] $Database = "OCAGDev"      

[string] $SQLQuery= $("SELECT * FROM [OCAGDev].[dbo].[CostOptimization1]")  

$Datatable = New-Object System.Data.DataTable      

$Connection = New-Object System.Data.SQLClient.SQLConnection  

$Connection.ConnectionString = "server='$SQLServer';database='$Database';trusted_connection=true;"  

$Connection.Open()  

$Command = New-Object System.Data.SQLClient.SQLCommand  

$Command.Connection = $Connection  

$Command.CommandText = $SQLQuery  

$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $Command  

$Dataset = new-object System.Data.Dataset  

$DataAdapter.Fill($Dataset)  

$Connection.Close()      

return $Dataset.Tables[0]  

}139529-error-db.png

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} vote

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.