SQL Server error on update command - "A severe error occurred on the current command"
Asked Answered
G

15

52

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.
Granddaddy answered 24/7, 2009 at 0:34 Comment(2)
There are 3 possibilities on the MS KB - 959028 - 910416 - 938102 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" EExteriorize
In my case, this occurred because I was low on disk space, and the DB didn't have room for both the change in the table(s) as well as the addition to the transaction log on-disk.Hinda
M
62

I just had the same error, and it was down to a corrupted index. Re-indexing the table fixed the problem.

Merkel answered 18/8, 2010 at 16:23 Comment(2)
I had exactly the same error today. The column throwing the error was not even involved with the index that was corrupted either.Toboggan
How did you find out that it was a corrupted index?Biz
A
12

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.

Antiquated answered 7/1, 2013 at 7:6 Comment(0)
B
6

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*'

Basie answered 24/7, 2009 at 0:39 Comment(2)
checktable didnt give anything, I will try to get access to the log files - thanks.Granddaddy
Also try DBCC CHECKDB(yourdb) to extend the check to the entire database. If you find dump files, look inside the newer sqldump*.txt files.Basie
P
6

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/

Pilloff answered 21/1, 2016 at 14:54 Comment(1)
Thank you for posting this, I just spent 3 hours of my life I'm never getting back on a similar issue. In my case it was a varchar I was trying to put into a decimal.Bogor
C
3

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

Covetous answered 12/4, 2017 at 22:14 Comment(1)
you might not want to ignore all SqlExceptions though. I made mine only skip if sqlEx.Message.Contains ("Operation cancelled by user."), else it throws/logs as usual. For instance, your sql might have a syntax error, and you'd want to know about that.Tewfik
S
3

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.
Shaer answered 6/6, 2019 at 17:33 Comment(3)
How did you find out what the real error was in your case?Biz
Sorry, I meant specifically how did you get that "transaction log for database '' is full" message to appear?Biz
We use Red Gate SQL Clone Server, and have a 1TB data license. In order to stay under the limit, I restore a production db to a dev environment, and truncate a bunch of data. One of my scripts had a bug in it, where I would first copy the last month of data to a temp table, truncate the original table, and insert the last month of data back into the main table. The insert bug was that instead of >= I had <=, and so I accidentally filled the tlog with 100 GB of data. On top of that, it turns out our IT department didn't configure alerts correctly, so nobody realized we were out of space.Shaer
I
1

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.

Imaginary answered 20/10, 2019 at 22:46 Comment(0)
D
1

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.

Darceldarcey answered 21/10, 2020 at 15:36 Comment(0)
U
1

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.

Unobtrusive answered 7/12, 2020 at 13:27 Comment(0)
C
0

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
Crosspurpose answered 28/8, 2020 at 11:46 Comment(0)
L
0

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).

Lithology answered 4/1, 2021 at 9:44 Comment(0)
N
0

Just wanted to add my 2cents to help whomever the next person that comes across this is.

We noticed that a specific report was failing after half an hour. I assumed it was a timeout as the amount of data being returned was huge. It turns out the SSRS default timeout setting is 1800 seconds (30mins). I changed the setting on this specific report to run indefinitely with no timeout and that resolved our issue.

Next step is to identify ways to improve the performance of the MSSQL behind the report :)

Neuralgia answered 14/6, 2022 at 3:21 Comment(0)
D
0

I had the same issue but the table was too big the I couldn't fix it from the UI or by dropping and creating all indexes. So here is another way to solve this , or at least it worked for me.

  1. I have backed up the database to a BAK file
  2. I have create a new database from newly backed up file and called the new database the same name but with appendix of "_BK" like this : myDatabase_BK
  3. The "bad table" on the new database was already working well without the error - so it seems that the deployment fixed the problem for the new database
  4. So what left was to rename the bad table on the live database(myDatabase) and then to create the same table from the backup (after renaming myDatabase.myTable):select * into myDatabase.myTable from myDatabase_BK.myTable
  5. Make sure to create all indexes on the new table.
Domash answered 19/6, 2022 at 7:14 Comment(0)
R
0

I received this same exception, but it was due to the fact that I was using Polybase to issue a query to an external table from an API request that was enlisting in a Transaction via TransactionScopes. The exception thrown from ADO.Net was the unhelpful: "A severe error occurred on the current command".

However, in SSMS, I did the following which finally made me realize that it was the transaction that was causing this issue:

  • View Object Explorer
  • Expand the Management Node
  • Expand SQL Server Logs
  • View the current log, and the errors that are logged when this exception was logged.

I saw the following:

Unsupported transaction manager request 0 encountered. SQL Server Parallel DataWarehousing TDS endpoint only supports local transaction request for 'begin/commit/rollback'.

I then placed this particular query in another transaction scope, suppressing the transactionscope that it would have enlisted in, and it worked.

using (var transactionScope = this.transactionScopeFactory.Create(
    System.Transactions.TransactionScopeOption.Suppress,
    new System.Transactions.TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted },
    System.Transactions.TransactionScopeAsyncFlowOption.Enabled))
{
    // ... query

    transactionScope.Complete(); // Suppress scope option renders this unnecessary, but just a good habit
}

Ritzy answered 3/11, 2022 at 19:40 Comment(0)
I
0

in my case, the number of fields in the temporary table did not match the number of fields received for the query from the linked server

    INSERT INTO #SomeTempTable
    EXEC [SomeLinkedServer].master.dbo.sp_executesql N'SELECT * FROM table'
Iguana answered 17/11, 2023 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.