Cannot continue the execution because the session is in the kill state - sql

I try to execute a update query in SQL Server 2016 (v13.0.5026.0) and get these error messages:
Msg 596, Level 21, State 1, Line 0
Cannot continue the execution because the session is in the kill state.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
Checked for corrupted index or anything
DBCC CheckDB (DBNAME) WITH NO_INFOMSGS, ALL_ERRORMSGS
--Returns no error
As Microsoft suggested update with the below link:
https://support.microsoft.com/en-us/help/4163478/fix-access-violation-when-incremental-statistics-automatically-updated
I tried an update to Cummulative Update(CU6) and changed to 13.0.5292.0
It says CU1 update has to fix it but doesn't solve the issue.
The query is:
UPDATE tableName
SET fieldName1 = 'a long query with some html tags and all it has 3600 chars'
WHERE fieldName2 = 12345
It doesn't have any special characters that SQL can't handle.
Any help would be great.

Related

TSQL RaiseError incorrect syntax, following MSDN's guidelines

MSDN states the following syntax:
RAISERROR ( { msg_id | msg_str | #local_variable }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]
The msg_str expects a string up to 2047 characters but truncates longer strings. It also has the possibility of substituting parameters, which truncates the message further than the number of characters provided by the values:
The error message can have a maximum of 2,047 characters. If the message contains 2,048 or more characters, only the first 2,044 are displayed and an ellipsis is added to indicate that the message has been truncated. Note that substitution parameters consume more characters than the output shows because of internal storage behavior. For example, the substitution parameter of %d with an assigned value of 2 actually produces one character in the message string but also internally takes up three additional characters of storage. This storage requirement decreases the number of available characters for message output.
When msg_str is specified, RAISERROR raises an error message with an error number of 50000.
The severity expects a number between 0 to 25, but corrects other numbers:
Severity levels from 0 through 18 can be specified by any user. Severity levels from 19 through 25 can only be specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity levels from 19 through 25, the WITH LOG option is required. Severity levels less than 0 are interpreted as 0. Severity levels greater than 25 are interpreted as 25.
The state expects values 0 to 255, but corrects subzero values:
[state] is an integer from 0 through 255. Negative values default to 1. Values larger than 255 should not be used.
The issue
I get the following errors when I run these queries:
RAISEERROR('Test', 20, 1);
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Test'.
DECLARE #err_message nvarchar(255);
SET #err_message = 'Test';
RAISEERROR(#err_message, 20, 1);
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'RAISEERROR'.
I can execute various other queries just fine. E.g.:
THROW 50001, 'Test', 1;
Msg 50001, Level 16, State 1, Line 1
Test
More info
SELECT ##VERSION produces this:
Microsoft SQL Server 2016 (RTM-GDR) (KB3194716) - 13.0.1722.0 (X64) Sep 26 2016 13:17:23 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows 8.1 Pro 6.3 (Build 9600: )
And the MSDN syntax was for "SQL Server (starting with 2008)" and as of writing, the article was updated October 19, 2016, which is months after the release of the SQL Server version I'm running.
What's going on here?
The docs:
MSDN states the following syntax:
RAISERROR
Your command:
RAISEERROR('Test', 20, 1);
I am always making this mistake. The command is not "Raise Error", but rather "Rais Error". I don't know why, but we're stuck with it...

Why SQL Server complains about non existing column, if the actual SQL is not executed?

I have the following SQL:
IF EXISTS (SELECT 1 FROM sys.columns WHERE name='RequireNamespaceClaim' AND object_id = OBJECT_ID('DefaultBaseUrl'))
BEGIN
UPDATE DefaultBaseUrl SET AuthenticationTypeId = at.AuthenticationTypeId
FROM DefaultBaseUrl dbu
JOIN (
SELECT AuthenticationTypeId, CASE CodeName WHEN 'NATIVE' THEN 0 ELSE 1 END RequireNamespaceClaim
FROM AuthenticationType
) at ON dbu.RequireNamespaceClaim = at.RequireNamespaceClaim
END
Running it prints:
Msg 207, Level 16, State 1, Line 8
Invalid column name 'RequireNamespaceClaim'.
However, running
SELECT 1 FROM sys.columns WHERE name='RequireNamespaceClaim' AND object_id = OBJECT_ID('DefaultBaseUrl')
reveals that no such column indeed exists.
So, the IF EXISTS statement is FALSE, hence the body of the if-statement does not run. However, the error is still printed.
What is going on?
How can I fix it?
SQL Server compiles the entire query and checks it for validity.
At that time the column doesn't exist.
There is a command to run an SQL from a string which is not compiled.
Have a look at (I think that's the right one):
http://technet.microsoft.com/en-us/library/ms175170(v=sql.105).aspx

Why am I receiving a SQL Insert procedure ERROR. Msg 60060?

I have the following query and error. Why am I receiving this error? I found nothing online via Google.
MSSQL query:
INSERT INTO [CEPrekyba].[dbo].[BK1$REFGoodUnit]
([GoodCode],[UnitCode],[UnitName],[IsCommon]
,[IsAccount],[Rate],[IsPack],[IsInteg]
,[IsSize],[Lenght],[Height],[Width]
,[Weight],[GrossWeight]
,[IsReusable],[ManualInserted])
VALUES ('530162','VNT','Gamintojas','1',
'1','1,00','0','0',
'0','0,00','0,00','0,00',
'0,00','0,00','0','1')
Error message:
Msg 60060, Level 16, State 1, Procedure sp_sRaiseError, Line 13
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.

SQL facing error while running bcp

i am facing error wile running this in sql server 2000
bcp "select dmedocno ,dmename,dmeauthor,dmekeywords from document
where repositoryid=4 and dmedocno between 1 and 60000 order by
dmedocno" queryout c:\LR_Query29_cutover_19_August.csv -Swsapp0772 -T -c -t","
Error is:
Server: Msg 103, Level 15, State 7, Line 1
The identifier that starts with 'select dmedocno ,dmename,dmeauthor,dmekeywords from document where repositoryid=4 and dmedocno between 1 and 60000 order by dmed' is too long. Maximum length is 128.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'queryout'.
why your sql server treats the query as identifier? hm...
Check default QUOTED_IDENTIFIER option for the server, try to set it to OFF

Returning Errors without a stored procedure

I need to know the number of rows in a certain table. If it is under 250 rows I need to return an error to the sql job forcing it to quit. The problem is it's not a stored procedure. It's sql code is running straight from the job step as a Transact-SQL script. Is this possible to return anything, or is there a better way to do this?
This is what I have:
select case when (select cnt = count([col]) from db.dbo.table) < 250 THEN 1 ELSE 0 END
You can use the RAISERROR command.
IF (SELECT COUNT([col] FROM db.dbo.table) < 250
RAISERROR('My error message', 15, 1)
The severity level 15 is a level that will indicate to the job that the command failed.
Look here for more about the RAISERROR command.