microsoft / SQLServerPSModule

This repo is the home of SQL Server PowerShell Module development.
MIT License
45 stars 1 forks source link

Invoke-SqlCmd fails with cryptic error message when running in 32-bit (x86) context. #52

Open Pxtl opened 1 year ago

Pxtl commented 1 year ago

To reproduce:

Launch Windows Powershell (x86) on a windows 10 machine.

Then execute

Invoke-SqlCmd 'Hello, WOrld'

Yields

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.
At line:1 char:1
+ Invoke-SqlCmd 'Hello, WOrld'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-Sqlcmd], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Now, it's perfectly reasonable that this module may not support running on 32-bit machines or there may be extra steps involved in making that happen, but a better error-message for this case would be appreciated. With the "BatchParser" error, the user does not know what caused the problem or what the resolution is.

AlexanderTrusheim commented 11 months ago

It seems like a similar issue applies to ARM64 machines. Using Invoke-SqlCmd 22.1.1, I get the following error when trying to Invoke any command against a remote SQL server:

Error while executing a SQL script. Microsoft.SqlTools.ServiceLayer.BatchParser.BatchParserException: Incorrect syntax was encountered while parsing ''. at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.RaiseError(ErrorCode errorCode, Token token, String message) at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.ExecuteBatch(Int32 repeatCount) at Microsoft.SqlTools.ServiceLayer.BatchParser.Parser.ParseLines() at Microsoft.SqlServer.Management.PowerShell.ExecutionProcessor.ExecuteTSql(String sqlCommand)

Matteo-T commented 6 months ago

Hi @Pxtl - are you getting that error with the v21 version of the module? If so, that's... by design, in the sense there's not much I can do right now. v22+ is the future, so try that instead and let me know.

@AlexanderTrusheim - that's a known issue and with Microsoft.Data.SqlClient finally available for ARM64, it should be a limitation/issue I can lift. I'll repurpose this issue to address it.

Pxtl commented 6 months ago

Ah, yes, you're right, I was in the process of migrating from v21 to v22 when I hit this, and I've checked it again and it is not a problem in v22. Sorry for the false alarm.