You left off the most important part of that second error (emphasis mine):
A severe error occurred on the current command. The results, if any, should be discarded.
Whatever the "application import node" is, it needs to deal with this error by discarding the resultset - and potentially undoing any work it did on the results that had been streamed in so far.
Any other solution would be a workaround, and likely an unsafe one.
It's important to note that, while KILL
ing the spid can cause this error, so can reading corrupt pages from disk. If you see this error unexpectedly, you should run DBCC CHECKDB
to make sure your data is safe.
...are you sure that connection via ODBC can catch this kind of error?
I wrote a small program in C# that creates an ODBC connection (using the System.Data.OdbcConnection
class) and starts streaming results from a long-running query:
using System.Data.Odbc;
try
{
var connection = new OdbcConnection("DSN=SQL2019");
var command = new OdbcCommand(@"SELECT * FROM dbo.Posts", connection);
connection.Open();
var reader = command.ExecuteReader();
while (reader.Read())
{
var id = reader.GetInt32(reader.GetOrdinal("Id"));
Console.WriteLine(id);
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
Each time I ran the program, I waited a few seconds and then issued a KILL
command on the spid that was running my query.
I tried this with four different ODBC drivers on my computer, and encountered errors from each one:

The errors I got were as follows:
ODBC Driver 17 for SQL Server
System.Data.Odbc.OdbcException (0x80131937): ERROR [08S01] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote host.
ERROR [08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure
SQL Server
System.InvalidOperationException: The connection has been disabled.
---> System.Data.Odbc.OdbcException (0x80131937): ERROR [01000] [Microsoft][ODBC SQL Server Driver][DBMSLPCN]ConnectionRead (recv()).
ERROR [08S01] [Microsoft][ODBC SQL Server Driver][DBMSLPCN]General network error. Check your network documentation.
SQL Server Native Client 11.0
System.Data.Odbc.OdbcException (0x80131937): ERROR [08S01] [Microsoft][SQL Server Native Client 11.0]TCP Provider: An existing connection was forcibly closed by the remote host.
ERROR [08S01] [Microsoft][SQL Server Native Client 11.0]Communication link failure
SQL Server Native Client RDA 11.0
Same as previous
All of that to say, the application should get an error on the connection that got killed. And it should have logic for dealing with the fact that the results might not have been complete when the query was killed.