dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Invoke-DbaQuery gives overload error for SQLCommand when specifying port on sql instance

Open AGregersen opened this issue 5 years ago • 6 comments

Verified issue does not already exist?

Yes

What error did you receive?

WARNING: [08:50:13][Invoke-DbaQuery] [udv-kb-sql4,4133] Failed during execution | Error connecting to [udv-kb-sql4,4133]: Cannot find an overload for "SqlCommand" and the argument count: "2".

Steps to Reproduce

# provide your command(s) executed pertaining to dbatools
# please include variable values (redacted or fake if needed) for reference

Invoke-DbaQuery -SqlInstance "udv-kb-sql4,4133" -Query "select * from sys.databases"

Are you running the latest release?

Yes

Other details or mentions

Using Get-DbaDatabase -SqlInstance 'udv-kb-sql4,4133' works fine

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name Value


PSVersion 7.1.4 PSEdition Core GitCommitId 7.1.4 OS Microsoft Windows 10.0.17763 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

SQL Server Edition and Build number

Microsoft SQL Server 2016 (SP2-CU17) (KB5001092) - 13.0.5888.11 (X64) Mar 19 2021 19:41:38 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

.NET 5.0.9

AGregersen avatar Oct 27 '21 06:10 AGregersen

This looks like you imported the module SqlServer prior to dbatools. See also #7627. Please try again on a clean powershell session without loading SqlServer module.

andreasjordan avatar Oct 27 '21 07:10 andreasjordan

It works from a clean session - might be a good idea to add that to the bug report template

AGregersen avatar Oct 27 '21 07:10 AGregersen

@wsmelton - As you designed the new bug report template: What do you think about adding a question about parallel install or usage of the SqlServer module?

andreasjordan avatar Oct 27 '21 07:10 andreasjordan

If this is an issue with sqlserver module being in the same session already that means this section of code is not running properly in PowerShell 7.1+.

https://github.com/sqlcollaborative/dbatools/blob/06a6a568fd451b5f23c25b0c7f18f8cfa83ffb3b/dbatools.psm1#L1051-L1059

On import we should be spitting out a warning that we found sqlserver loaded in the session.

wsmelton avatar Oct 27 '21 10:10 wsmelton

This looks like you imported the module SqlServer prior to dbatools. See also #7627. Please try again on a clean powershell session without loading SqlServer module.

Is this possible with the ISE? I can't see where I have any profiles (none of the scripts mentioned in the environment variables for the profile exist), and trying to remove-module for sqlserver and sqlps results in "no modules were removed".

mbourgon avatar Jan 06 '23 15:01 mbourgon

@mbourgon the ISE will load multiple modules without telling you because of the Command Explorer feature it has. When it first loads up it will search for modules and can start loading the help for those commands, which requires the module to be imported.

VS Code is now preferred because it does not experience this issue. The ISE has a custom host that won't react the same as PowerShell.exe or even the PowerShell Extension terminal in VS Code.

wsmelton avatar Jan 06 '23 16:01 wsmelton