SQL Server Cancel Execution in SSMS vs Kill (SPID) - sql-server

What is the difference between cancel execution in SSMS and using kill(spid). In testing, I've discovered that when you cancel an execution, using kill (spid) with statusonly returns the error that the rollback operation is not in progress.
It's probably applicable to all recent versions of SQL Server, but in my case I'm using 2017. SSMS is V18.

KILL will rollback a transaction, cancelling the execution of a command will stop the query at the soonest opportunity and will not automatically roll it back.

Related

Infinite rollback - SQL Server 2016

I have a strange situation. An script (dele from ...) was running at SQL Managment Studio in a VM machine but this machine died on the night, the process apparently was not affected but I did the kill to start the process again.
Now I have a infinite rollback, today the rollback complete 1 week, my feelings said to not restart the service and wait forever. I want to stop de rollback even with data loss in the table.
Someone Know how can I stop the rollback?

(SQL) Server Agent Job not stopping

I am using SQL Server 2016, and have some Jobs running in the SQL Server Agent. Today I found one of the job is taking too long (10hours!) to run and is still processing, so I try to stop that. I tried right-click and stop the job, it showed a success message. However, when I go to the Job Activity Monitor, it is showing that the job is still running! I also tried the following code:
USE [msdb]
GO
EXEC dbo.sp_stop_job N'Process Reserving MI (except problematic tables)'
GO
It also says the job stopped successfully. But again when I go to the Job Activity Monitor, it is showing that the job is still running!
Can any one please help?
At the end I have to ask the server team to reboot the server in order to solve this problem

Whenever I kill a Select query on SQL Server Always On Cluster, it goes to ROLLBACK and hangs

Whenever I kill a Select query on SQL Server Always On Cluster, it goes to ROLLBACK and hangs.
Do I need to stop the synchronous commit mode with the secondary and then kill the session and then start the sync ?
it goes to ROLLBACK and hangs.
this may appear to be hang,but it is rolling back internally
Do I need to stop the synchronous commit mode with the secondary and then kill the session and then start the sync ?
this wont make any difference ,since the log blocks should be replicated and will replicate once you resume always on
Let the query rollback

Locked by wait type OLEDB with SQL server 2012

I have a batch process that generate one linked server over huge Excel files to fetch data into SQL Server 2012
Sometimes the process is locked by a wait type "OLEDB"
I can't find the root ause but my biggest problem is that I can't kill the process that has the wait_type OLEDB
I have try
KILL spid
Not works, never kill the spid.
SPID 90: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.
ALTER DATABASE [DataMigration] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
But never finish (due PRINT_ROLLBACK_PROGRESS)
If I look into the process, I see the file that cause the block, but I don't know how solve the issue
SELECT * FROM SYSPROCESSES where spid=90
-There is any way to kill this process without restart the servers?
-How can avoid the wait type OLEDB? the same file in the same location usually works fine, the process hangs only some times.
This is quite simple. OLEDB as a wait type often indicates some wait on another Server. This is also the reason why you can't kill the process. OLEDB is often (not always) used as a wait type for connections between SQL Server instances.
You kill the connection on your server, but if the process is running on another instance/linked server it will run there too. It will kill the process after the process on the other instance is finished.
So much to the bad news. The good news for you is, that you easily can find the query which runs on another linked server using this query:
SELECT spid, waitresource
FROM sys.sysprocesses
WHERE spid = <yourKilledSpid>
Just filter it for the spid you try to kill. The waitresource will indicate the remote server including the spid on the remote server. Go to the remote server and kill the spid there too. Your connection will immediately be killed/rolledback. Hopefully this solves your issue.
You can additionally try to take a look at the waiting_tasks. Maybe you'll see something helpful like a blocking resource in there.
SELECT *
FROM sys.dm_os_waiting_tasks

Database Table lock

I'm using SQL 2000 for my application. My application is using N tables.
My application has a wrapper for SQL server called Database server. It is running as a 24/7 windows service.
If I have checked the integrity check option in the SQL maintenance plan, when this task is running one time after that one of my tables has been locked and it has been never unlocked.
So my history of the database transaction has been lost.
Please provide your suggestion how to solve this problem.
What if you have a client-side command timeout? And the locks are your own locks as a result of the DBCC?
Your code will timeout waiting for the DBCC to finish, but any locks it's already issued are not rolled back.
A command timeout tells SQL Server to simply stop processing. To release locks you need to either ROLLACK on the connection or close the connection.
Options:
Use SET XACT_ABORT in the SQL: Do I really need to use “SET XACT_ABORT ON”? (SO)
On client error, try and rollback yourself (Literally IF ##TRANCOUNT > 0 ROLLBACK TRAN)

Resources