In our program (C#), we use the system stored procedure sp_cursorprepexec.
Now, on a somewhat newer customer environment, we get the following error message:
Cannot continue the execution because the session is in the kill state. A severe error occurred on the current command. The results, if any, should be discarded.
Recording the program crash on SQL Server Profiler shows the following error message:
Exception ex_trans_cexcept.
SQL Server Version there is "Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)
Sep 24 2019 13:48:23
Copyright (C) 2019 Microsoft Corporation
Standard Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)"
Script
declare #p1 int
set #p1=NULL
declare #p2 int
set #p2=0
declare #p7 int
set #p7=default
exec sp_cursorprepexec #handle=#p1 output,#cursor=#p2 output,#paramdef=N'#0 int, #1 int, #2 int, #3 varchar(50), #4 varchar(10)',#stmt=N'Select *
From [TABLE]
Where CustomerNumber = #0
And VersionNumber = #1
And ContactNumber = #2
And (om_db.[CUSTOMER]_AccessValidation (#3, BankAccountId, #4, ''Read'', ''DO.BankAccount'') = 1)
Order by AccountNumber, CustomerNumber, VersionNumber, ContactNummer, AccountIdentifier',#scrollopt=4097,#ccopt=98305,#rowcount=#p7 output,#0=205536,#1=0,#2=14,#3='[CUSTOMER]',#4='[USER]'
select #p1, #p2, #p7
Solution description
changing the compatibility level of the database from SQL Server 2019 (150) to SQL Server 2017 (140) solved the problem.
Does anyone has a clue what probably could cause this error?
Related
Strange situation... New physical severs, new install of SQL Server 2019 Enterprise version :
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ).
Testing the performance by creating the first database like this :
CREATE DATABASE DB_BENCH
GO
DECLARE #SQL NVARCHAR(max) = N'';
SELECT #SQL = #SQL + N'ALTER DATABASE DB_BENCH MODIFY FILE (NAME = ''' + name + N''', SIZE = 10 GB, FILEGROWTH = 64 MB);'
FROM DB_BENCH.sys.database_files;
SET #SQL = #SQL + N'ALTER DATABASE DB_BENCH SET RECOVERY SIMPLE;'
EXEC (#SQL);
GO
And the objects in the database like this :
USE DB_BENCH
GO
SET NOCOUNT ON;
GO
CREATE TABLE T_TIME_INTERVAL_TIV
(TIV_ID INT NOT NULL IDENTITY PRIMARY KEY,
TIV_GROUP INT,
TIV_DEBUT DATETIME2(0),
TIV_FIN DATETIME2(0))
GO
TRUNCATE TABLE T_TIME_INTERVAL_TIV;
GO
BULK INSERT T_TIME_INTERVAL_TIV
FROM "C:\DATA_SQL\intervals.txt"
WITH (KEEPIDENTITY ,
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n');
GO
CREATE VIEW V
AS
SELECT TIV_GROUP AS id, TIV_DEBUT AS intime, TIV_FIN AS outtime
FROM T_TIME_INTERVAL_TIV
GO
The intervals.txt datafile contains 1 million lines.
You can have it at :
https://1drv.ms/t/s!AqvZfiQYoNpBiCD65D4zaRbch5s-?e=UicEYu
The query that produce the bug :
WITH T1 As
(SELECT id, intime
FROM #T
UNION ALL
SELECT id, outtime FROM #T),
T2 As
(SELECT ROW_NUMBER() OVER(PARTITION BY id ORDER BY intime) NN, id, intime
FROM T1 T1_1),
T3 As
(SELECT T2_1.NN - ROW_NUMBER() OVER(PARTITION BY T2_1.id ORDER BY T2_1.intime,T2_2.intime) NN1,
T2_1.id, T2_1.intime intime, T2_2.intime outtime
FROM T2 T2_1
INNER JOIN T2 T2_2
ON T2_1.id=T2_2.id
And T2_1.NN=T2_2.NN-1
WHERE EXISTS (SELECT *
FROM V S
WHERE S.id=T2_1.id
AND (S.intime < T2_2.intime AND S.outtime>T2_1.intime))
OR T2_1.intime = T2_2.intime)
SELECT id, MIN(intime) intime, MAX(outtime) outtime
FROM T3
GROUP BY id, NN1
ORDER BY id, intime, outtime;
We tested this query on 2 different servers... with the same SQL Server installation.
The result is always :
Msg 601, Level 12, State 1, Line ...
Could not continue scan with NOLOCK due to data movement.
With an installation of :
SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)
There is no problem...
We tested the databases with DBCC CHECKDB () WITH DATA_PURITY. No errors.
Can you reproduce with your different editions/patches (CU) and give me your results for which are alright or not ?
If some of you have already the bug I will add an entry in SQL Azure feedback...
Thanks
After many investigation, we found that it is really a SQL Server bug.
The bug disappear when we execute a :
UPDATE STATISTICS T_TIME_INTERVAL_TIV WITH FULLSCAN;
Or when whe "hint" the query with OPTION (MAXDOP 1)
Sometime a stack dump appear (not Always) showing this type of messages :
A time-out occurred while waiting for buffer latch -- type 4, bp 0000029BA883BDC0, page 9:407, stat 0x10b, database id: 2, allocation unit Id: 422212465393664/140737488683008, task 0x0000029B86723848 : 14, waittime 300 seconds, flags 0x1a, owning task 0x0000029B86713848. Not continuing to wait.
Which is the tempdb. A Stack Dump is systematically recorded on file.
We will call the MS hotline as soon as possible.
Thanks to all of you.
The following code works in my local instance of Sql Server but fails in remote instance with error Can you please help me out on this. Getting Error#
102: Incorrect syntax near '$.Location'
If (len(#JsonBODetails) > 0)
Begin
Insert Into #Temp_BOLines
SELECT * FROM
OPENJSON ( #JsonBODetails )
WITH (
Location varchar(2) '$.Location' ,
JCA varchar(4) '$.JCA'
)
End
Edit: SQL Server version. It is the same in both the cases.
Microsoft SQL Server 2017 (RTM-CU13-OD) (KB4483666) - 14.0.3049.1 (X64)
Dec 15 2018 11:16:42
Copyright (C) 2017 Microsoft Corporation
Web Edition (64-bit) on Windows Server 2016 Datacenter 10.0 (Build 14393: ) (Hypervisor)
Adding the complete procedure to repro this error
declare #JsonBODetails varchar(max)
SELECT * FROM
OPENJSON ( #JsonBODetails )
WITH (
Location varchar(2) '$.Location' ,
JCA varchar(4) '$.JCA'
)
Interestingly enough I found no post for this specific, but basic issue.
Goal: update the latest budgetid record docstatus = 0. Then I want to update the next-to-last budgetid record docstatus = 1. I am trying this within PHP but also testing in my SQL Server SEM and it is failing there, too.
My SQL Server statement:
select
budgetid, docstatus, datechanged
from
ccy_budget
where
activityid = 11111
order by
datechanged desc
limit 1,1;
Error that occurs in SEM is:
Incorrect syntax near 'limit'.
Yet in w3schools this [sample] sql works just fine:
SELECT *
FROM Customers
ORDER BY postalcode DESC
LIMIT 1,1;
Seems so simple, surely I am missing something fundamental.
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
Apr 2 2010 15:48:46
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
Equivalent syntax in SQL Server would be
select *
from table
order by somerow desc
offset 1 rows fetch next 1 rows only;
But the above is available from SQL Server 2012 on, so for your version, you have to some thing like below
;with cte
as
(
select *,row_number() over (order by postalcode desc) as rn
from table
)
select * from cte where rn=2
Calling PRINT from a child stored procedure causes:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
How to make it not give an error?
Note: Not SQL Server 2005
i have a stored procedure
ALTER PROCEDURE [dbo].[Archive_SessionDeleteOnly] AS
SET XACT_ABORT ON
BEGIN DISTRIBUTED TRANSACTION
EXECUTE ASILIVE.ContosoLive.dbo.Archive_Delete
ROLLBACK TRANSACTION
PRINT 'Fargodeep Mine'
With the child stored procedure being:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
PRINT 'You no take candle'
When i run my outer procedure Archive_SessionDeleteOnly it all runs to completion, including the PRINT after the call to my child stored procedure
You no take candle
Fargodeep Mine
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
The entire operation runs to completion, but i get an error:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
If i remove the print from the "child" stored procedure:
ALTER PROCEDURE [dbo].[Archive_Delete] AS
--PRINT 'You no take candle'
it runs without error.
i've also tried randomly adding NOCOUNT (since nobody knows how to fix it anyway):
ALTER PROCEDURE [dbo].[Archive_Delete] AS
SET NOCOUNT ON
PRINT 'You no take candle'
it still causes:
Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
ServerA: SQL Server 2000
SELECT ##version
Microsoft SQL Server 2000 - 8.00.818 (Intel X86) May 31 2003 16:08:15 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
ServerB: SQL Server 2000
SELECT ##version
Microsoft SQL Server 2000 - 8.00.2055 (Intel X86) Dec 16 2008 19:46:53 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
There are no errors in either SQL Server Error Log.
How can i make SQL Server not choke when a PRINT is used in a child stored procedure. i have other cases where i call print from child stored procedures, without error.
Update Trimmed down to minimal reproducible case. Exact sql is shown
Seems to be an issue with SQL 2000 when the query is run from Management Studio
Have you tried running it in Query Analyzer?
is there a fix for the crash in SQL-Server 2005 Management Studio when you try to open a design-query-editor with a sql-statementent preceding USE database;?
For example:
USE DB1;
SELECT * FROM Table1;
If you mark SELECT * FROM Table1;, you can open the editor succesfully.
If you mark both lines, SSMS will crash with a "Microsoft SQL Server Management Studio has stopped working"-Dialog(with the option to debug or close SSMS) and some additional information on this problem f.e.:
Problem signature:
Problem Event Name: BEX
Application Name: SqlWb.exe
Application Version: 2005.90.5000.0
Application Timestamp: 4d02772b
Fault Module Name: vdt80.dll
Fault Module Version: 8.0.50727.1826
Fault Module Timestamp: 480d6e41
Exception Offset: 0032ae42
Exception Code: c0000409
Exception Data: 00000000
OS Version: 6.1.7601.2.1.0.16.7
SQL-Server version:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
9.00.5000.00 SP4 Enterprise Edition (64-bit)
OS:
Windows Server 2008 R2 Standard(SP 1)
Edit: this problem also occurs if i try to open the designer with T-SQL Statement like:
IF EXISTS(
SELECT *
FROM ClosingDate
WHERE DATEDIFF(DAY, DATEADD(DAY, -1, GETDATE()). ClosingDate) = 0
) UPDATE Table2 SET
Column1 = 255
WHERE
Column1 = 1
sure, take out the use db statement and change the code to this:
select * from DB1.dbo.Table1
this syntax will allow you to select data from other databases on the same server in which you are not in the context of.