Reputation: 508
I receive the following exception while connecting Azure SQLDB with Invoke-SQLCMD PowerShell command.
$conn = 'Server=tcp:MyServer.database.windows.net,1433;Database=MyDB;Authentication=Active Directory Integrated;Encrypt=True;'
$sql = 'SELECT * FROM sys.databases'
Invoke-Sqlcmd -ConnectionString $conn -Query $sql
Exception:
Invoke-Sqlcmd: Keyword not supported: 'authentication'.
I did some research. It is something to do with MS client libraries:
Looks like the first one needs to be replaced with the second one (don't know how to do that). There are bunch of suggestions for VS Studio and C#, but nothing concrete for PowerShell invoke-sqlcmd command.
I installed .net core framework as well as the latest .net framework. But no luck.
Update: I noticed that this is a problem only in VSCode! The code works fine in PowerShell ISE
Upvotes: 0
Views: 336
Reputation: 8422
Try installing Microsoft.Data.SqlClient
In Vs code as below:
Check PowerShell Version in VSCode: Agreed with @AlwaysLearning Ensure that you are using the same version of PowerShell in both VSCode and PowerShell ISE. You can check the PowerShell version in VSCode by running:
PowerShell command:
$PSVersionTable.PSVersion
Make sure it matches the version you are using in PowerShell ISE.
Make sure you are using the latest version of Visual Studio Code and the PowerShell extension. Updates can sometimes fix compatibility issues.
Upvotes: 1