Search

invoke-sqlcmd does not return T-SQL Errors by cmille19

Closed
as Fixed Help for as Fixed

16
0
Sign in
to vote
Type: Bug
ID: 779320
Opened: 2/15/2013 10:53:35 AM
Access Restriction: Public
0
Workaround(s)
5
User(s) can reproduce this bug
invoke-sqlcmd does not return errors. Settings with or without outputsqlerrors, abortonerror, severitylevel or errorlevel do not work as documented. This is unexpected behavior when compared to SSMS sqlcmd.exe which correctly return errors.

Details (expand)

Product Language

English

Version

SQL Server 2008 R2 SP1

Category

Tools (SSMS, Agent, Profiler, Migration, etc.)

Operating System

Windows 7 Enterprise

Operating System Language

English

Steps to Reproduce

invoke-sqlcmd -ServerInstance YourServer -Database tempdb -Query "select 1/0" -OutputSqlErrors $true -AbortOnError -SeverityLevel 0 -ErrorLevel 0

-- No errors returned regardless of various output parameters. While sqlcmd.exe does return an error:

sqlcmd.exe -S "YourServer" -d tempdb -Q 'select 1/0'
Msg 8134, Level 16, State 1, Server YourServer, Line 1
Divide by zero error encountered.

Actual Results

No output, No errors

Expected Results

In general errors should be returned instead of silently continuing. Specific to this example the error message should be:

Msg 8134, Level 16, State 1, Server YourServer, Line 1
Divide by zero error encountered.

Platform

 

Virtualization

 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Sethu Srinivasan on 5/8/2013 at 3:47 PM
Hello Kyle,
We have a fix for this issue. Please let us know if you would be willing to help us validate this fix on your test machine



Thanks
Sethu Srinivasan [MSFT]
Posted by Kyle Neier on 5/8/2013 at 5:26 AM
Any update on where this is fixed? It appears to still be broken. However, If you put a select statement prior to the statement that is in error, it seems the errors are made available.

This returns nothing - regardless of what you put in as OutputSqlErrors or SeverityLevel:
invoke-sqlcmd -ServerInstance ".\SQL2012" -Query 'select 1/0'

This returns an error:
invoke-sqlcmd -ServerInstance ".\SQL2012" -Query 'select 1;select 1/0'

As does this:
invoke-sqlcmd -ServerInstance ".\SQL2012" -Query 'select 1;select 1/0' -OutputSqlErrors $true

This does not (which is expected behavior):
invoke-sqlcmd -ServerInstance ".\SQL2012" -Query 'select 1;select 1/0' -OutputSqlErrors $false

If you use InputFile, the leading select statement must be within the batch (between GO statements) that the error occurs. Running a select at the beginning of the file does not work for errors in a different batch.

Thanks!
Posted by cmille19 on 3/1/2013 at 7:56 PM
This connect was marked as fixed. What version and SP/CU is it fixed in? Can you provide any details?
Posted by lkh on 2/15/2013 at 11:23 AM
I am working with Powershell v3 ISE on Windows Server 2008 R2. I cannot figure out how to execute "only" a stored procedure specified in the -Query parameter of Invoke-Sqlcmd and get back any SQL error. This includes any use of -ErrorVariablea-OutputSqlErrors1-Verbose-AbortOnError-ErrorActionStop.

I am testing with divide by zero in a sproc. The error returns as expected in SSMS, SSIS, Sqlcmd from cmd prompt and '& Sqlcmd' in PowerShell. Invoke-Sqlcmd does return errors from a SELECT statement or from a stored procedure like this -Query "SELECT 1;EXEC dbo.usp_WithError".
Sign in to post a workaround.