[sql-server] SQL Server error on update command - "A severe error occurred on the current command"

Running the following query in SQL Server Management Studio gives the error below.

update table_name set is_active = 0 where id  = 3

A severe error occurred on the current command. The results, if any, should be discarded.

  • The logs have been truncated
  • there is an update trigger but this isnt the issue
  • the transaction count is zero (@@trancount)

I have tried the same update statement on a couple of other tables in the database and they work fine.

DBCC CHECKTABLE('table_name');

gives

DBCC results for 'table_name'.
There are 13 rows in 1 pages for object "table_name".
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

This question is related to sql-server sql-server-2005 tsql

The answer is


I was having the error in Hangfire where I did not have access to the internal workings of the library or was I able to trace what the primary cause was.

Building on @Remus Rusanu answer, I was able to have this fixed with the following script.

    --first set the database to single user mode
    ALTER DATABASE TransXSmartClientJob
    SET SINGLE_USER
    WITH ROLLBACK IMMEDIATE;
    GO

    -- Then try to repair
    DBCC CHECKDB(TransXSmartClientJob, REPAIR_REBUILD)

    -- when done, set the database back to multiple user mode
    ALTER DATABASE TransXSmartClientJob
    SET MULTI_USER;
    GO

A different scenario but the same error: I got this error when I was trying to insert records into a temporary table using a stored procedure. It turned out there was a parameter mismatch. I was trying to insert a BIGINT into an INT.

Credit goes to Vicky Harp: http://vickyharp.com/2012/03/troubleshooting-a-severe-error-occurred-on-the-current-command/


In my case it was something else, += operator caused this. I had to replace += X with field = field + X to overcome this. I assume this is a bug though I wasn't able to find any related KB on Microsoft sites.

I am using SQL Server 2008 R2(10.50.1600).


This seems to happen when there's a generic problem with your data source that it isn't handling.

In my case I had inserted a bunch of data, the indexes had become corrupt on the table, they needed rebuilding. I found a script to rebuild them all, seemed to fix it. To find the error I ran the same query on the database - one that had worked 100+ times previously.


This error is exactly what it means: Something bad happened, that would not normally happen.

In my most recent case, the REAL error was:

Msg 9002, Level 17, State 2, Procedure MyProcedure, Line 2 [Batch Start Line 3]
The transaction log for database 'MyDb' is full due to 'LOG_BACKUP'.

Here is my checklist of things to try, perhaps in this exact order:

  1. Check if you're out of disk space (this was my real problem; our NOC did not catch this)
  2. Check if you're low on memory
  3. Check if the Windows Event Log shows any serious system failures like hard drives failing
  4. Check if you have any unsafe code loaded through extended procedures or SQLCLR unsafe assemblies that could de-stabilize the SQLServer.exe process.
  5. Run CheckDB to see if your database has any corruption issues. On a very large database, if this stored procedure only touches a sub-set of tables, you can save time by seeing which partitions (filegroups) the stored procedure touches, and only checking those specific filegroups.
    1. I would do this for your database and master db as well.

in my case, the method: context.Database.CreateIfNotExists(); called up multiple times before create database and crashed an error A severe error occurred on the current command. The results, if any, should be discarded.


In my case, I was using System.Threading.CancellationTokenSource to cancel a SqlCommand but not handling the exception with catch (SqlException) { }


One other possible solution we just found after having this issue across multiple databases/tables on the same server.

Is the max connections open to the sql server. We had an app that wasn't closing it's SQL connection and was leaving them open so we were running around 28K-31K connections (SQL Sever has a max out at 32K ish), and we noticed that once we killed a few thousand sleeping connections it took care of the error listed on this question.

The fix was to update the apps to make sure they closed their connections instead of leaving them open.


There are 3 possibilities on the MS KB

When I see stuff like this: I always think hotfix, engine, server errors etc.

4 results: search for ""Msg 0, Level 11,State 0, Line 0" A severe error occurred on the current command"

Edit: It's on MS Connect too


Run DBCC CHECKTABLE('table_name');

Check the LOG folder where the isntance is installed (\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG usually) for any file named 'SQLDUMP*'


In my case,I was using SubQuery and had a same problem. I realized that the problem is from memory leakage.

Restarting MSSQL service cause to flush tempDb resource and free huge amount of memory. so this was solve the problem.


Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to sql-server-2005

Add a row number to result set of a SQL query SQL Server : Transpose rows to columns Select info from table where row has max date How to query for Xml values and attributes from table in SQL Server? How to restore SQL Server 2014 backup in SQL Server 2008 SQL Server 2005 Using CHARINDEX() To split a string Is it necessary to use # for creating temp tables in SQL server? SQL Query to find the last day of the month JDBC connection to MSSQL server in windows authentication mode How to convert the system date format to dd/mm/yy in SQL Server 2008 R2?

Examples related to tsql

Passing multiple values for same variable in stored procedure Count the Number of Tables in a SQL Server Database Change Date Format(DD/MM/YYYY) in SQL SELECT Statement Stored procedure with default parameters Format number as percent in MS SQL Server EXEC sp_executesql with multiple parameters SQL Server after update trigger How to compare datetime with only date in SQL Server Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot Printing integer variable and string on same line in SQL