Powershell script to connect to azure sql db
Mohammed Sohel
66
Reputation points
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,
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]
}
Windows for business | Windows Server | User experience | PowerShell
Sign in to answer