RaviLobo
RaviLobo

Reputation: 508

Invoke-sqlcmd raises exception "Keyword not supported: 'authentication'" while connecting to Azure SQL DB

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:

  1. System.Data.SqlClient
  2. Microsoft.Data.SqlClient

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

Answers (1)

Pratik Lad
Pratik Lad

Reputation: 8422

Try installing Microsoft.Data.SqlClient In Vs code as below:

  • Add the extension Nuget Package Manager GUI .
  • Then Select the View from pull down manual. Choose Command Palette. In the Command Palette select Nuget Package Manager GUI
  • .The Nuget Package Manager GUI will appear. Select Install New Package. Type Microsoft.Data.SqlClient in the search bar then click Search. Click Install enter image description here

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

Related Questions