FIX: No error is prompted when connection is terminated in sqlcmd

Symptoms

Assume that you use the sqlcmd utility to connect to a remote instance of Microsoft SQL Server 2012 or SQL Server 2014 and run a query with the -Q and -b option. When the sqlcmd connection is terminated unexpectedly before the query is finished, the exit code of sqlcmd indicates success.

Note
  • The expected outcome is that when the sqlcmd connection is terminated, an error message is reported by sqlcmd that indicates that the connection is lost and the exit code is 1 that indicates failure.
  • The sqlcmd connection can be terminated in these ways: the SQL Server KILL command, SQL Server service shutdown, SQL Server restart during patching, network issues, and others.

Resolution

After you apply this update, an error message together with severity 19 is sent back for the conditions described previously.

The issue was first fixed in the following cumulative update of SQL Server:
Recommendation: Install the latest cumulative update for SQL Server

Workaround

To work around this issue, use -i option instead of -Q option in sqlcmd to specify a query file that contains multiple query batches.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Properties

Article ID: 3082877 - Last Review: 22 Dec 2015 - Revision: 1

Feedback