I am trying to use Invoke-Sqlcmd command in PowerShell (version 7):
$Server = 'localhost'
$Database = 'db'
$Query = "PRINT 'This is output'"
$Username = 'root'
$Password = 'pass'
Invoke-SQLCmd -ServerInstance $Server -Database $Database -ConnectionTimeout 2 -QueryTimeout 5 -Query $Query
But getting error:
Invoke-Sqlcmd: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Invoke-Sqlcmd:
I can connect to DB using Workbench and using mysql command from powershell, but Invoke-Sqlcmd returns this error every time, can anyone point me where the problem is?