更改为READ COMMITTED后,隔离级别仍为SERIALIZABLE [英] Isolation level is still SERIALIZABLE after change to READ COMMITTED

查看:117
本文介绍了更改为READ COMMITTED后,隔离级别仍为SERIALIZABLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有一个事务范围,我没有设置任何隔离级别(默认情况下应该是可序列化的?)。在将一些进程和参数传递到数据库/存储过程(默认在SQL中提交读取)之后,隔离级别仍然是可序列化的。



我的问题是我怎么能将隔离级别设置为为整个进程提交读取(从代码到存储过程执行)?我已经尝试了很多方法,但隔离级别仍然被卡在序列化中。



我检查了函数,它不是嵌套函数调用。这是一个直接的函数调用,没有任何其他函数调用我的函数。



任何帮助将不胜感激。谢谢。



我的尝试:



1.套装代码中的READ COMMITTED隔离级别如下:

Hi, I have a transaction scope in my codes in which I did not set any isolation level(by default should be serializable?). After some process and parameters is passed into databse/stored procedure(default is read committed in SQL), the isolation level is still serializable.

My question is how can I set the isolation level to read committed for the whole process(from codes until stored procedure execution)? I have tried many methods but the isolation level is still being stuck as serializable.

I have checked the function and it is not nested function calling. It is a direct function call and there is no any other function that is calling my function.

Any help would be appreciated. Thank you.

What I have tried:

1. Set the isolation level as READ COMMITTED in codes as below:

TransactionOptions transOps = new TransactionOptions();
transOps.IsolationLevel = IsolationLevel.ReadCommitted;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionUtil.GetTransactionOptions()))
{
   //do something here
}



2.将存储过程中的隔离级别设置为读取提交,如下所示:


2. Set isolation level in stored procedure to read committed as below:

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

推荐答案

你的GetTransactionOptions()有什么作用?在我看来,你将transOps设置为ReadCommited,但是然后调用Get方法返回TransactionOptions的其他一些实例。



试试这个变化:



What does your GetTransactionOptions() do? It seems to me you're setting transOps to ReadCommited, but then call Get method to return some other instance of TransactionOptions.

Try this variation:

TransactionOptions transOps = TransactionUtil.GetTransactionOptions();
transOps.IsolationLevel = IsolationLevel.ReadCommitted;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transOps))
{
   //do something here
}





在GetTransactionOptions设置断点并检查返回的值。



作为替代方法,删除GetTransactionOptions完全:





Set a breakpoint at GetTransactionOptions and check the returned value.

As an alternative, remove GetTransactionOptions completely:

TransactionOptions transOps = new TransactionOptions();
transOps.IsolationLevel = IsolationLevel.ReadCommitted;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transOps))
{
   //do something here
}





我希望这会有所帮助。



I hope this helps.


这篇关于更改为READ COMMITTED后,隔离级别仍为SERIALIZABLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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