3

I'm running the following command (smallest reproducible example I could come up with):

Invoke-Sqlcmd "select * from sys.databases"  | %{
    Invoke-Sqlcmd "select 1"     
}

I'm getting the following error:

Invoke-Sqlcmd : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "pipeline.resources" was correctly embedded or linked into assembly "System.Management.Automation" at compile time, or that all the satellite assemblies required are loadable and fully signed. At line:1 char:1 + Invoke-Sqlcmd "select * from sys.databases" | %{ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidResult: (:) [Invoke-Sqlcmd], MissingManifestResourceException + FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Tired this:

  • both with ISE and command line
  • both elevated ("run as administrator") and not
  • against SQL 2012 and SQL 2008
  • from a Windows 8 and from Server 2008

In all cases the result is the same.

Why and how to diagnose?

Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
  • I am trying to understand what is the significance of `select 1`. The first `Invoke-Sqlcmd` works for me, and I am able to pipe it to print database names. However, I see the same error on using `select 1` – Srikanth Venugopalan Aug 06 '13 at 05:48
  • @SrikanthVenugopalan I believe it's a combination of both. Select 1 is obviously working fine on it's own. – Andrew Savinykh Aug 06 '13 at 05:53

1 Answers1

5

I've also noticed issues using invoke-sqlcmd to chain together invoke-sqlcmd commands via pipeline. A workaround which seems to address issue, save the output of first command to variable then pipe output to next invoke-sqlcmd call.

$databases = Invoke-Sqlcmd "select * from sys.databases"  
$databases | % { Invoke-Sqlcmd "select 1" }
Chad Miller
  • 40,127
  • 3
  • 30
  • 34
  • Yep, this is what I ended up with. Looks like Invoke-Sqlcmd is not quite re-entrant, eh? – Andrew Savinykh Aug 06 '13 at 20:11
  • There are several other issues with invoke-sqlcmd. A more serious issue is around error handling where invoke-sqlcmd will quietly swallows errors. Use invoke-sqlcmd with caution: https://connect.microsoft.com/SQLServer/feedback/details/779320/invoke-sqlcmd-does-not-return-t-sql-errors – Chad Miller Aug 06 '13 at 20:26
  • Yes, I've noticed some other issues as well. – Andrew Savinykh Aug 06 '13 at 20:30