I’ve been using Visual Code to do all my PowerShell programming lately (instead of the PowerShell ISE). I’ve created several scripts that use Invoke-SqlCmd and they’ve all worked fine in VS Code until today.
A simple test like:
Invoke-Sqlcmd -Query 'SELECT @@VERSION' -ConnectionString 'Data Source=myserver;Initial Catalog=master;Integrated Security=True;'
… now gives this error when run in Visual Code:
Invoke-Sqlcmd : Could not load file or assembly ‘Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91’ or one of its dependencies. The system cannot find the file
specified.
The exact same code, when run in the PowerShell ISE on the same machine, runs fine. Both the ISE and VS Code are running PS 5.1.
Get-Module -Name "SqlServer"
… in both PS ISE and VS Code shows:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 21.1.18256 SqlServer {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp, Add-SqlAzureAuthenticationContext...}
I’m at a loss as to how to get this working in VS Code again. Last week, I installed Visual Studio 2022 on this computer, and I wonder if that changed something that broke VS Code.
Any suggestions?