# Invoke-SqlCmd suddenly stopped working

**URL:** <https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760>\
**Category:** PowerShell Help\
**Created:** [March 7, 2022, 9:41pm UTC](https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760 "2022-03-07T21:41:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shontz](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@shontz](https://forums.powershell.org/u/shontz)\
**Post date:** [March 7, 2022, 9:41pm UTC](https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760/1 "2022-03-07T21:41:07Z")

</div>

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:

```auto
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.

```auto
Get-Module -Name "SqlServer"

```

… in both PS ISE and VS Code shows:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 7, 2022, 9:52pm UTC](https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760/2 "2022-03-07T21:52:08Z")

</div>

> [@shontz](#):
>
> Any suggestions?

UnInstall Visual Studio 2022  
ReInstall VSCode and all extensions and modules you’re using.

---

<div class="post-metadata">

**Author:** ![shontz](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@shontz](https://forums.powershell.org/u/shontz)\
**Post date:** [March 15, 2022, 4:24pm UTC](https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760/3 "2022-03-15T16:24:49Z")

</div>

I eventually figured it out - Visual Studio Code was running the 32-bit version of PowerShell 5.1. Once I told it to use the 64-bit version, Invoke-SqlCmd worked properly.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/invoke-sqlcmd-suddenly-stopped-working/18760/4 "2024-05-16T20:18:10Z")

</div>

Closed on May 16, 2024, 8:18pm UTC


