', 50,150,7500,1002) go
Step Two: Create two transactions that will cause deadlocks
Transaction 1:
SET NOCOUNT on;
SET xact_abort on;
Go-use Try-catch to cause code errors and continue to run the
begin TRY
begin TRAN
UPDATE dbo.goods_sort SET ssortname= ' Women's Shoes ' WHERE isortid=1003;
WAITFOR DELAY ' 00:00:05 ';
UPDATE dbo.goods SET sgoodsname= ' fatty down jacket ' WHERE iid=2;
COMMIT TRAN End
TRY
BEGIN CATCH
IF (xact_state () =-1)
ROLLBACK TRAN;
A--error_number () value of 1
programs/databases, where this t_sql syntax is used3\ analysis to find and solve the problemEG:/*-------------------------------------------------------The database deadlock is caused by the 71 process number, which executes the following SQL syntaxEventType Parameters EventInfo-------------- ---------- ------------------------------------------------Language Event 0SELECT * FROM TestInsert test VALUES (1,
Label:First, a scalar-valued function, Diglock, is used to recursively detect if there is a lock loop for each session in SQL Server, and if the function eventually returns 1, the lock loop is detected (that is, a deadlock is detected), and if the final return of 0 indicates that no lock loop is detected. 1 CREATE FUNCTION [dbo].[Diglock]
2 (
3 @spid int,
4 @orginSpid int
5 )
6 RETURNS bit
7 as
8 B
correct, should every request error Ah, now is dozens of times only one or two times the error, certainly not this reason.Search on the internet for half a day, no fruit, so put the code on the server to simulate concurrent testing, or there will be one or two times the error, but the report of the error is very clear
CREATE TABLE
#tmp_lock_who
(ID int identity (1,1), spid smallint,bl smallint) IF @ @ERROR
@ @ERRORinsert into
#tmp_lock_who (SPID,BL) Select
0, Blockedfrom (SELECT * from sysprocesses where
BLOCKED>0)
A Where NOT EXISTS (SELECT * from sysprocesses where blocked>0)
b where a.blocked=spid) union select spid,blocked from sysprocesses where
Blocked>0if
@ @ERROR
@intCountProperties = Count (*), @in
Post by: Mladen prajdi IK: immediate deadlock configurations without changing existing code
In myPrevious postAbout immediate deadlock events in SQL Server 2005 I 've shown a way to use a try catch block to get the deadlock error.
The con of this method, although it uses
What is a deadlock?
====================
A deadlock occurs when two system server process IDs (SPIDs) are waiting for a resource and neither process can advance because the other process is preventing it from getting the resource. for example, Andrew holds a lock on table A and requests a lock on table B; Lindsay holds a lock on table B and requests a lock on table.
What can lead to deadlocks?
============
this time, we can use the following stored procedures to detect the process and SQL statements that cause the deadlock. The built-in system stored procedures sp_who and sp_lock of SQL Server can also be used to find blocking and deadlocks, but the method described here is not easy to use.
Use masterGoCreate procedure sp_who_lockAsBeginDeclare @ spid int, @ bl
This article is reproduced articles, the description is very good, has not been verified.I've recently encountered a deadlock problem that seems strange and interesting to analyze. This deadlock seems to be hard to understand. In the analysis process, a lot of typical methods of parsing SQL Server deadlock are used. Do
for OracleA, landing in SYSDBA status of PL/SQL or WorksheetB, query the current number of connectionsshow parameter processes;C, change the number of system connectionsalter system set processes=1000 Scope=spfile;d. Create Pfilecreate Pfile from SPFile;E. Restart the Oracle service or restart the Oracle serverafter the change, the error point is c3p0 setting parameters, no reported apparent
Project on-line, before the preparation of the acceptance of a serious problem: many SELECT statements as a deadlock of the sacrifice, most of the report cannot be opened. It's a big problem. All reports are inaccessible, and our report is placed on the TV carousel, and the TV is in the factory, so after the problem, the whole factory knows.To solve this problem is more tortuous, first of all, the colleague who wrote the SAP interface found the proble
identity (1, 1), spid smallint, bl smallint) IF @ ERROR
@ ERRORinsert
# Tmp_lock_who (spid, bl) select
0, blockedfrom (select * from sysprocesses where
Blocked> 0)
A where not exists (select * from sysprocesses where blocked> 0)
B where a. blocked = spid) union select spid, blocked from sysprocesses where
Blocked> 0IF
@ ERROR
@ IntCountProperties = Count (*), @ intCounter = 1 from # tmp_lock_whoIF
@
A deadlock occurs if two user processes lock different resources and then attempt to lock resources that are locked by the other. At this point, SQL Server automatically selects and aborts one of the processes to unlock the deadlock, allowing another process to continue processing. The system will rollback the aborted transaction and send an
output is as follows: The code is as follows:Copy code DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.TraceFlag Status---------------1204 11205 13605 1 (The number of affected rows is 3)DBCC execution is complete. If DBCC outputs an error message, contact the system administrator.After that, you can view the routine logs of the database. The database che
SQL Server query and Kill deadlock statement, sqlserverkill
Query deadlock process statements
select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT'
Statement used to kill a deadlock
kill spid
Next, I will share with you a piece of inform
Querying a stored procedure for SQL Server database deadlockThe use of SQL Server as a database application system will not be able to avoid the occasional deadlock. After the deadlock appears,Most maintenance personnel or developers will only use sp_who to find the deadlock
These days in a project, not how to engage in a lot of threads before, and now start, only learn to do the side.At the beginning, the program error is, is the hint of a deadlock, just beginning, I have no experience, thought is the program code deadlock, with lock code, the program to lock up, run the program, found that there is a time-out phenomenon, access to
The server SQL Server database does not automatically generate a trace file as Oracle does when a deadlock occurs. Blocking information can sometimes be seen in [admin]->[Current Activity] (sometimes SQL Server Enterprise Manager will not respond because there are too many locks).
Set Track 1204:
Use MASTERDBCC Traceon (1204,-1)
Displays the status of all trace f
@intCountProperties = Count (*), @intCounter = 1From #tmp_lock_whoIF @ @ERROR If @intCountProperties =0Select ' now has no blocking and deadlock information ' as message--Cycle startWhile @intCounter Begin--Take the first recordSelect @spid = spid, @bl = blFrom #tmp_lock_who where Id = @intCounterBeginIf @spid =0Select ' Cause database deadlock is: ' + CAST (@bl
:
DBCC Traceon (1222,-1)
Go
DBCC Tracestatus
To simulate another deadlock, the "Win" Connection query (the one that was not killed) is restarted, and then the deadlock lost session is restarted, and a second deadlock occurs after a few seconds.
After a deadlock occurs, stop another query that execu
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.