Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 invoke-sqlcmd bug?

Author  Topic 

sticky
Starting Member

2 Posts

Posted - 2009-09-16 : 21:03:53
Hi,

I've been banging my head against the wall trying to get the invoke-sqlcmd powershell cmdlet to correctly execute my stored procedures.

Consider the following:


CREATE PROCEDURE test
AS
BEGIN
-- SELECT 'A'
SELECT 'B' WHERE 1=2
SELECT 'C'
END


Which when executed using sqlcmd.exe:


C:\Program Files\Microsoft SQL Server\100\Tools\Binn>SQLCMD.EXE -s server -d db -Q "exec test"

-

-
C

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>


Returns a blank recordset then 'C' as expected.

But when executed using invoke-sqlcmd:


PS C:\> Invoke-Sqlcmd -ServerInstance server -Database db -Query "EXEC test"
PS C:\>


Doesn't return anything. I believe the blank recordset is screwing up the output somehow, preventing anything after the select statement from being displayed.

Interestingly, if you output a non-blank recordset before the blank recordset, everything else runs ok. I.e, if you uncomment the line SELECT 'A' statement in the procedure, the output is now:


PS C:\> Invoke-Sqlcmd -ServerInstance server -Database db -Query "EXEC test"

Column1
-------
A
C


PS C:\>


This has been driving me nuts as I want to output an error if a blank recordset is returned. But with invoke-sqlcmd behaving like this, the error doesn't get returned.

I've verified that the code after the blank recordset does get executed by putting in a few update statements after it, it just appears to stop outputting to screen.

Does anyone else experience this problem and/or have a workaround/explanation? Is it a bug?

Thanks

sticky
Starting Member

2 Posts

Posted - 2009-09-20 : 22:08:01
No takers? If someone could at least verify this behaviour then I'll submit a bug request to Microsoft.
Go to Top of Page
   

- Advertisement -