TransactionScope和死锁 [英] TransactionScope and dead lock

查看:94
本文介绍了TransactionScope和死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个api,它具有复杂的业务逻辑,它可以捕获大约5或6个不同的表。 API包含在Transaction Scope中,当我运行多线程来调用api时,会抛出DeadLock异常。 


我试图理解


1。对于MSDN文档中的TransactionScope类,ThreadSafeType是什么意思。这是否意味着整个区块内的cope片段被锁定?


2。数据库在执行更新时是否锁定整个表或仅锁定事务中涉及的记录,以及当SELECT语句被锁定在API之外时是否可以运行SELECT语句(另一个API在其中一个名为$ b的表上查询SELECT语句步骤1中的$ b。


我运行SQL分析器,我看到了带有索引名称的DeadLock图,但它没有告诉我对该表运行了什么语句。


 


请提供建议。


 


 

解决方案

你好,


 


欢迎来到EF论坛!


 


< span style ="font-size:12pt"> 你在这里使用EF吗? 
 


< span style ="font-size:12pt">  


此外,为了更好地理解TransactionScope,我建议你参考这个MSDN文档,
http:// msdn .microsoft.com / zh-CN / library / ms172152(VS.90).aspx  


 


TransactionScope是线程安全的,这意味着它可以在多线程环境下正常工作。  


 


对于第二个问题,它实际上取决于您使用的隔离级别。
   有关详情,请参阅
http://msdn.microsoft.com/en-us/library/ms172001(SQL.100).aspx


http://blogs.msdn.com/b/angelsb/archive/2004 /07/27/199261.aspx


 


美好的一天!


< span style ="font-size:12pt">  


 


最诚挚的问候,$
Lingzhi Sun


MSDN用户支持
在论坛


< span style ="font-size:12pt"> 如果您对我们的支持有任何反馈,请联系
msdnmg@microsoft.com


I have one api which has complex business logic and it spams about 5 or 6 different tables. The API is wrapped with Transaction Scope, and when I run multi-threads to call the api, DeadLock exception is being thrown. 

I am trying to understand

1. what does it mean by ThreadSafeType for the TransactionScope class in MSDN documentation. Does that mean the cope snippet within the whole block is locked?

2. Does the DB lock the whole table or just the records involved within the transaction when doing update and if a SELECT statement can be run when it's being locked outside of the API (a different API is querying SELECT statement on one of the tables called in Step1).

I run the SQL profiler and I saw the DeadLock graph with the index name but it does not tell me what statements are run against the table.

 

Please advise.

 

 

解决方案

Hello,

 

Welcome to EF forum!

 

Are you using EF here?   

 

Besides, to understand TransactionScope better, I would recommend you refer to this MSDN document, http://msdn.microsoft.com/en-us/library/ms172152(VS.90).aspx. 

 

TransactionScope is thread safe which means it can work well under multi-threads environment.  

 

For the second question, it actually depends on what isolation level you are using.   For detail, please see http://msdn.microsoft.com/en-us/library/ms172001(SQL.100).aspx

http://blogs.msdn.com/b/angelsb/archive/2004/07/27/199261.aspx

 

Good day!

 

 

Best Regards,
Lingzhi Sun

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


这篇关于TransactionScope和死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆