开发者

Invoke-Sqlcmd unavailable from the ISE, but works in conventional Powershell host

I'm having some trouble with Invoke-Sqlcmd

From the normal pow开发者_运维技巧ershell console, it's fine. But I'm unable to use it from the ISE.

I can confim the addin is loaded

>Get-PSSnapin SqlServerCmdletSnapin100
Name        : SqlServerCmdletSnapin100
> add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin : Cannot add ... SqlServerCmdletSnapin100 ... it is already added.

when I try to use it

> Invoke-Sqlcmd
The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function ...

Any ideas on what the issue could be?


Don't know. I get a different error because I have ISE set to run with 4.0

Invoke-Sqlcmd : Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.


Did you also add the provider snapin:

Add-PsSnapin sqlserverprovidersnapin100

Both are required for full functionality.


I don't see the behavior you are seeing. On 64-bit Windows, the SqlServerCmdletSnapin100 snapin appears to be 64-bit only. Any chance you are trying to use it from a 32-bit ISE? Check the title bar. If it say "Windows PowerShell 2.0 (x86)" then you're running the 32-bit ISE?


In one script that required SqlServerCmdletSnapin100 i used this workaround:

$Name = SqlServerCmdletSnapin100
$Snapin = Get-PSSnapin -Name $Name -ErrorAction SilentlyContinue
if($Snapin -ne $null) {
    Remove-PSSnapin $Name 
}
Add-PSSnapin $Name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜