Click here to Skip to main content
15,913,836 members
Home / Discussions / Database
   

Database

 
GeneralRe: Synchronising number of disconnected databases to a central DB. Pin
Mycroft Holmes15-Dec-15 11:44
professionalMycroft Holmes15-Dec-15 11:44 
GeneralRe: Synchronising number of disconnected databases to a central DB. Pin
Eddy Vluggen15-Dec-15 11:53
professionalEddy Vluggen15-Dec-15 11:53 
QuestionSQL Server deadlocks Pin
Member 1115415113-Dec-15 6:42
Member 1115415113-Dec-15 6:42 
GeneralRe: SQL Server deadlocks Pin
Kornfeld Eliyahu Peter13-Dec-15 7:17
professionalKornfeld Eliyahu Peter13-Dec-15 7:17 
GeneralRe: SQL Server deadlocks Pin
Member 1115415113-Dec-15 19:41
Member 1115415113-Dec-15 19:41 
GeneralRe: SQL Server deadlocks Pin
Kornfeld Eliyahu Peter13-Dec-15 20:23
professionalKornfeld Eliyahu Peter13-Dec-15 20:23 
GeneralRe: SQL Server deadlocks Pin
Member 1115415113-Dec-15 20:36
Member 1115415113-Dec-15 20:36 
GeneralRe: SQL Server deadlocks Pin
Member 1115415114-Dec-15 0:00
Member 1115415114-Dec-15 0:00 
The situation is much more complex than I thougth it was.
The deadlock happened between the primary key of the table and the index of the same table. I really do not know why. A workaround that I found is to use SELECT 1 FROM EDEFADDERS WITH (TABLOCKX, HOLDLOCK) insted of UPDATE EDEFADDERS SET ID = ID.
Here is the scripts that you need to reproduced it. (I believe complete and correct!!!)
Script to create the table:
SQL
CREATE TABLE EDEFADDERS(
	id varchar(32) NOT NULL,
	adderkind int NOT NULL,
	description varchar(30) NOT NULL,
	formula text NOT NULL,
	transkind int NOT NULL,
	addedset varchar(255) NULL,
	removedset varchar(255) NULL,
	adderdecs int NOT NULL,
PRIMARY KEY CLUSTERED (id ASC) 
)

CREATE NONCLUSTERED INDEX EDEFADDERS_I1 ON EDEFADDERS (adderkind ASC)

INSERT INTO EDEFADDERS VALUES ('088162994983574692C347CE326582BD', 0, 'Πληρ. Μετρητοίς', '"Συνολική Αξία"', 2, 41, , 0)
INSERT INTO EDEFADDERS VALUES ('0DCE2805DF7E4B4C875649128C16A14C', 0, 'Εισπρ. Εμβασμ.', '"Συνολική Αξία"', 1, 24, , 0)
INSERT INTO EDEFADDERS VALUES ('1072EB880FABF8459B99EC38058B6CA1', 2, 'Εισπράξεις Γραμ.', '"Συνολική Αξία"', 1, 22, , 0)
INSERT INTO EDEFADDERS VALUES ('142F006F40F0DA4C80ACEA477E2B5662', 0, 'Εκπτώσεις Χονδρ.', '"Αξία Εκπτωσης" + "Πιστωτικό Εκπτωσης" * "Καθαρή Αξία"', 5, 70,72,80, 73,74,83, 0)
INSERT INTO EDEFADDERS VALUES ('1D4E3250AFD52343A1680A4387BA1490', 0, 'Εισπρ. Μετρητοίς', '"Συνολική Αξία"', 1, 21, , 0)
INSERT INTO EDEFADDERS VALUES ('22A60A4EC35EC14E8AD82B97A5906572', 2, 'Εισπράξεις Επιτ.', '"Συνολική Αξία"', 1, 23, , 0)
INSERT INTO EDEFADDERS VALUES ('24B3B31AD780124B888C5D935966F679', 3, 'Επιστροφές Μετρ.', '"Συνολική Αξία"', 2, 49, , 0)
INSERT INTO EDEFADDERS VALUES ('273FED73284E5E4689BAA7F913173086', 0, 'Εκπτ. Ειδών Χ.', '"Αξία Εκπτωσης Είδους"', 5, 70,72,80, 73,83, 0)
INSERT INTO EDEFADDERS VALUES ('3034E6BD63AF114A8DEB61B442C8D873', 0, 'Πωλήσεις Π.Υ. Λ.', '"Καθαρή Αξία"', 5, 84, , 0)
INSERT INTO EDEFADDERS VALUES ('349B9E68AE2D104689B6E2E67C618A8E', 0, 'Εκπτώσεις Π.Υ.Χ.', '"Αξία Εκπτωσης"', 5, 78, 79, 0)
INSERT INTO EDEFADDERS VALUES ('3708771B165CD74E81323BCBDE14CEC7', 2, 'Εισπράξεις Μετρ.', '"Συνολική Αξία"', 1, 21, , 0)
INSERT INTO EDEFADDERS VALUES ('38570F0087D3D94D838C4219E713F0FA', 0, 'Εισπρ. Πιστ.Καρτ', '"Συνολική Αξία"', 1, 26, , 0)
INSERT INTO EDEFADDERS VALUES ('3AC77B713D3FB546947FE018C7B2BF7E', 0, 'Πληρ. Εμβασμ.', '"Συνολική Αξία"', 2, 44, , 0)
INSERT INTO EDEFADDERS VALUES ('4259AB5FE2C25C4DA9C975E24F42BA4F', 0, 'Πωλήσεις Λιαν.', '"Καθαρή Αξία"', 5, 76,82, 77, 0)
INSERT INTO EDEFADDERS VALUES ('4AF5EDBA1B0BED4CB4085F3B8D567AA1', 0, 'ΠΩΛ.ΑΝΑ ΚΑΤΗΓΟΡΙ', '"Καθαρή Αξία" *(( inset ( "Πωλητής/Αντιπρόσωπος" , '1' )) AND ( "Κατηγορία Είδους" = 01 ))', 5, 70,72,74, 73,79, 0)
INSERT INTO EDEFADDERS VALUES ('4BD015E24E739C4292009DB18DA2AED3', 1, 'Σύν.Εκπτ.Πελατών', '"Αξία Εκπτωσης Πελάτη"', 5, 70,72,78, 73,74,79, 0)
INSERT INTO EDEFADDERS VALUES ('5390C0D7C85DE44797C2AF36B46FD441', 0, 'Ποσοτ. Εκπτ. Χ.', '"Αξία Εκπτωσης Τιμοκαταλόγου"', 5, 70,72,80, 73,83, 0)
INSERT INTO EDEFADDERS VALUES ('5986CE3CE649D14BA0E7DC9138DC24C9', 0, 'Πωλήσεις Χονδρ.', '"Καθαρή Αξία"', 5, 70,72,80, 73,74,83, 0)
INSERT INTO EDEFADDERS VALUES ('5A2A9016A3C57A4CB6FD3FD9D3B5E40E', 0, 'Πιστωτικά Εκπτ.', '"Καθαρή Αξία"', 5, 74, , 0)
INSERT INTO EDEFADDERS VALUES ('5AC130A23482C345B581091BA5504859', 0, 'Αθρ. Επιχ. 31', '"Καθαρή Αξία" *(( inset ( "Πωλητής/Αντιπρόσωπος" , '1 - 2' )) AND ( "Κατηγορία Είδους" = 01 ))', 5, 70,72,74, 73,79, 0)
INSERT INTO EDEFADDERS VALUES ('5B61F8A2D361014484234E50AEC99045', 0, 'Λοιπές Εξαγωγές', '"Καθαρή Αξία"', 5, 11, , 0)
INSERT INTO EDEFADDERS VALUES ('5D59097BF887F240801FFAF200B427A6', 0, 'Αγορές Χονδρικής', '"Καθαρή Αξία"', 4, 40,42, 43,44,49, 0)
INSERT INTO EDEFADDERS VALUES ('604F30B7A1CB434D9F7DADD59A9B9A74', 0, 'Εκπτώσεις Πελ. Χ', '"Αξία Εκπτωσης Πελάτη"', 5, 70,72,80, 73,83, 0)
INSERT INTO EDEFADDERS VALUES ('641899F5AFF050479F9454573841EC8E', 3, 'Πληρωμές Αντικ.', '"Συνολική Αξία"', 2, 45, , 0)
INSERT INTO EDEFADDERS VALUES ('6523E3A73BAD414EA534954D1C21106E', 0, 'Πληρ. Γραμματ.', '"Συνολική Αξία"', 2, 42, , 0)
INSERT INTO EDEFADDERS VALUES ('666D15457C526B4FBF96539E20BBE802', 2, 'Εισπρ. Εμβασμ.', '"Συνολική Αξία"', 1, 24, , 0)
INSERT INTO EDEFADDERS VALUES ('706E587CF5A1E648939391046C5FA117', 3, 'Πληρωμές Επιταγ.', '"Συνολική Αξία"', 2, 43, , 0)
INSERT INTO EDEFADDERS VALUES ('714F6D3207A8BD4BACDAD6FCB86F774B', 1, 'Σύν.Ειδικών Εκπτ', '"Ειδική Εκπτωση"', 5, 70,72,78, 73,74,79, 0)
INSERT INTO EDEFADDERS VALUES ('73C057D1EFC0C440AB42AB2E43E59ED7', 0, 'Εισπρ. Αντικατ.', '"Συνολική Αξία"', 1, 25, , 0)
INSERT INTO EDEFADDERS VALUES ('77D6C0A98A289F4F92FCBA462DC78449', 0, 'Ειδικές Εκπτ. Χ.', '"Ειδική Εκπτωση"', 5, 70,72,80, 73,83, 0)
INSERT INTO EDEFADDERS VALUES ('7CC5CEDDAB8D8746AD7B1D7E315B75DE', 0, 'ΠΩΛΗΣΕΙΣ', '"Καθαρή Αξία"', 5, 70,72,76,78,82,84, 73,74,79,83, 0)
INSERT INTO EDEFADDERS VALUES ('82A8E1B3BF46D04EB1DC0CB178FE15BB', 2, 'Εισπρ. Αντικατ.', '"Συνολική Αξία"', 1, 25, , 0)
INSERT INTO EDEFADDERS VALUES ('8F8A505724081E4AB510EEE90A4F58C1', 1, 'Σύν.Εκπτ. Ειδους', '"Αξία Εκπτωσης Είδους"', 5, 70,72,78, 73,74,79, 0)
INSERT INTO EDEFADDERS VALUES ('90499A1A8954D741A1C076735E4C4B6E', 3, 'Πληρωμές Εμβασμ.', '"Συνολική Αξία"', 2, 44, , 0)
INSERT INTO EDEFADDERS VALUES ('97CCD23F1432954EBABBE391B0945CE9', 0, 'Εκπτώσεις Λιαν.', '"Αξία Εκπτωσης"', 5, 76,82, 77, 0)
INSERT INTO EDEFADDERS VALUES ('9E0D358AECAE0A47BD0D27CE8A8FFCF3', 0, 'Εκπτώσεις Π.Υ.Λ.', '"Αξία Εκπτωσης"', 5, 84, , 0)
INSERT INTO EDEFADDERS VALUES ('A084AC5553C52544B4B053DF77817265', 2, 'Εισπρ. Πιστ. Κ.', '"Συνολική Αξία"', 1, 26, , 0)
INSERT INTO EDEFADDERS VALUES ('A0CDBA5347B1CD48B2119BE5C007F3C5', 0, 'Εισπρ. Επιταγών', '"Συνολική Αξία"', 1, 23, , 0)
INSERT INTO EDEFADDERS VALUES ('A329C05004756C4EBAACA1B5F269DE1F', 0, 'Αθρ. Επιχ. 32', '"Καθαρή Αξία" *(( inset ( "Πωλητής/Αντιπρόσωπος" , '1 - 2' ))*( inset ( "Κατηγορία Είδους" , '1 - 2' )))', 5, 70,72,74, 73,79, 0)
INSERT INTO EDEFADDERS VALUES ('B175031C0CA3364193E39C41FC29A262', 2, 'Επιστροφές Μετρ.', '"Συνολική Αξία"', 1, 29, , 0)
INSERT INTO EDEFADDERS VALUES ('B54944B81669EF498F3E2D55B5F8ECD5', 1, 'Σύν.Ποσοτ. Εκπτ.', '"Αξία Εκπτωσης Τιμοκαταλόγου"', 5, 70,72,78, 73,74,79, 0)
INSERT INTO EDEFADDERS VALUES ('B6527AFBC4B345469C4B81D1B768504F', 0, 'Πληρ. Επιταγών', '"Συνολική Αξία"', 2, 43, , 0)
INSERT INTO EDEFADDERS VALUES ('BE5E6E822BF0D946918436C3F9F28737', 0, 'Αγορές Παρ.Υπηρ.', '"Καθαρή Αξία"', 4, 46, 47, 0)
INSERT INTO EDEFADDERS VALUES ('C5D6BFD587A11948949446161E501015', 3, 'Πληρωμές Μετρητ.', '"Συνολική Αξία"', 2, 41, , 0)
INSERT INTO EDEFADDERS VALUES ('CABA8202B260F046945AD56CCAD51A56', 0, 'Εκπτ. Τρ.Πληρ. Χ', '"Αξία Εκπτωσης Τρόπου Πληρωμής"', 5, 70,72,80, 73,83, 0)
INSERT INTO EDEFADDERS VALUES ('CDEAFE4EF039DD4A9A7721A35BC949AA', 1, 'Σύν.Εκπτ.Τρ.Πληρ', '"Αξία Εκπτωσης Τρόπου Πληρωμής"', 5, 70,72,78, 73,74,79, 0)
INSERT INTO EDEFADDERS VALUES ('CE97BE8509223145B274049AE6EABBF4', 0, 'Πωλήσεις Π.Υ. Χ.', '"Καθαρή Αξία"', 5, 78, 79, 0)
INSERT INTO EDEFADDERS VALUES ('D051DCEB86DFAB4BA3B564A1B4570CED', 3, 'Πληρωμές Γραμ.', '"Συνολική Αξία"', 2, 42, , 0)
INSERT INTO EDEFADDERS VALUES ('EC08552E3FDBA14189D39418D5571545', 0, 'Εισπρ. Γραμμ.', '"Συνολική Αξία"', 1, 22, , 0)
INSERT INTO EDEFADDERS VALUES ('FEB6C6CE84571F4A98558A515A822C47', 0, 'Πληρ. Αντικατ.', '"Συνολική Αξία"', 2, 45, , 0)


Script to run it twice (simultaneously) that will produce the deadlock:
C#
begin tran myTran
 
declare @exec datetime, @i int, @m varchar(2), @x int
set @exec = getdate()
set @m = substring(convert(varchar, @exec, 120), 15, 2)
set @x = convert(int, @m) + 1
 
print 'Before Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
update EDEFADDERS set ID = ID
print 'After Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
 
while datediff(ms, @exec, convert(datetime, substring(convert(varchar, @exec, 120), 1, 14) + right('00' + rtrim(ltrim(convert(varchar, @x))), 2) + ':00.000')) > 0
begin
	set @exec = getdate()
end
 
print 'Before Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
update EDEFADDERS set ID = ID
print 'After Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
 
commit tran myTran


Script to workaround the problem:
C#
begin tran myTran
 
declare @exec datetime, @i int, @m varchar(2), @x int
set @exec = getdate()
set @m = substring(convert(varchar, @exec, 120), 15, 2)
set @x = convert(int, @m) + 1
 
print 'Before Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
SELECT 1 FROM EDEFADDERS WITH (TABLOCKX, HOLDLOCK)
print 'After Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
 
while datediff(ms, @exec, convert(datetime, substring(convert(varchar, @exec, 120), 1, 14) + right('00' + rtrim(ltrim(convert(varchar, @x))), 2) + ':00.000')) > 0
begin
	set @exec = getdate()
end
 
print 'Before Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
SELECT 1 FROM EDEFADDERS WITH (TABLOCKX, HOLDLOCK)
print 'After Lock EDEFADDERS for 2nd time. Time = ' + convert(varchar(40), getdate())
 
commit tran myTran


Sorry to anyone I mislead.
SuggestionRe: SQL Server deadlocks Pin
Richard Deeming14-Dec-15 2:50
mveRichard Deeming14-Dec-15 2:50 
GeneralRe: SQL Server deadlocks Pin
Member 1115415116-Dec-15 2:28
Member 1115415116-Dec-15 2:28 
Questionneed to consult about project discussion Pin
divinity technologies10-Dec-15 22:14
divinity technologies10-Dec-15 22:14 
AnswerRe: need to consult about project discussion Pin
Mycroft Holmes11-Dec-15 1:26
professionalMycroft Holmes11-Dec-15 1:26 
QuestionCreating Access database with VB6 Pin
Member 121949778-Dec-15 18:05
Member 121949778-Dec-15 18:05 
AnswerRe: Creating Access database with VB6 Pin
Mycroft Holmes8-Dec-15 20:46
professionalMycroft Holmes8-Dec-15 20:46 
GeneralRe: Creating Access database with VB6 Pin
Member 121949778-Dec-15 21:03
Member 121949778-Dec-15 21:03 
GeneralRe: Creating Access database with VB6 Pin
Mycroft Holmes9-Dec-15 1:23
professionalMycroft Holmes9-Dec-15 1:23 
AnswerRe: Creating Access database with VB6 Pin
CHill609-Dec-15 5:29
mveCHill609-Dec-15 5:29 
GeneralRe: Creating Access database with VB6 Pin
Member 121949779-Dec-15 21:18
Member 121949779-Dec-15 21:18 
GeneralRe: Creating Access database with VB6 Pin
CHill6010-Dec-15 5:23
mveCHill6010-Dec-15 5:23 
QuestionHow to update sequence in MySQL Pin
Jassim Rahma8-Dec-15 4:10
Jassim Rahma8-Dec-15 4:10 
AnswerRe: How to update sequence in MySQL Pin
CHill608-Dec-15 4:40
mveCHill608-Dec-15 4:40 
QuestionGiving access permissions to user webadminqa_iispool Pin
indian1434-Dec-15 12:23
indian1434-Dec-15 12:23 
AnswerRe: Giving access permissions to user webadminqa_iispool Pin
Mycroft Holmes4-Dec-15 13:03
professionalMycroft Holmes4-Dec-15 13:03 
AnswerRe: Giving access permissions to user webadminqa_iispool Pin
Richard Deeming7-Dec-15 1:34
mveRichard Deeming7-Dec-15 1:34 
QuestionHow to manage 1000 millions of record in Mysql database Pin
Member 120698693-Dec-15 20:28
Member 120698693-Dec-15 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.