Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell x86: Could not load file or assembly Microsoft.SqlServer.BatchParser

When I try to do an invoke-sql command from Powershell X86 I get an error

invoke-sqlcmd -Query "SELECT 'HELLO!'" -ServerInstance Server -Database DB

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.

If I run the exact same command from regular x64 Powershell prompt I do not get the error

invoke-sqlcmd -Query "SELECT 'HELLO!'" -ServerInstance Server -Database DB
Column1
-------
HELLO!

This is on a newly built windows 2016 x64 bit server:

OS Name Microsoft Windows Server 2016 Datacenter Version 10.0.14393 Build 14393

I need x86 powershell to run a script that uses a legacy 32 bit ODBC driver, it also uses invoke-sql commands as well.

like image 622
user313720 Avatar asked May 31 '26 13:05

user313720


1 Answers

As mentioned in some other comments, it may be related to the bit version. If that is the case, you can start a job with the -RunAs32 flag for it to act like a 32-bit namespace and then return any data through the Receive-Job CMDlet

# I am 64-bit land
$job_handle = Start-Job -RunAs32 -ArgumentList "Relevant Data" -ScriptBlock {
    Param ( [string]$stuff_i_need )

    # I am 32-bit land

    return "Complete"
}

# I am 64-bit land (again)
$result = $job_handle | Wait-Job | Receive-Job

Note that it will be forced to use a namespace so any relevant data will need to be passed in

like image 159
SlaQr Avatar answered Jun 02 '26 13:06

SlaQr