.net事务无法选择数据 [英] .net transaction not able to select data

查看:87
本文介绍了.net事务无法选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我今天又回来了一个问题。



我有ADO将数据插入表的.NET应用程序。 (ex发票)



我在我的ADO.net应用程序中使用c#代码编写了与IsolationLevel.ReadUncommitted的交易



每当我运行这个应用程序并尝试从我的发票表中选择数据时,我都无法这样做。



ex:

当我在运行ADO.net应用程序时从我的SQL查询窗口查询下面的查询时,

以下查询有效,

从发票中选择*(nolock,nowait)



以下查询不起作用,

从发票中选择*



我知道当我们使用(nolock,nowait)时,我们可以读取未提交的数据,但我想只读取已提交的数据,但似乎事务正在锁定我的表并且不允许我读取任何数据。 />


我想只阅读提交的数据。



我尝试过的事情:



我试过IsolationLevel.ReadCommitted,IsolationLevel.ReadUnCommitted in my ado.net申请





请建议在这种情况下可以做些什么。

Dear All,

I am back with one more problem today.

I have ADO.NET application which inserts data to table. (ex Invoices)

I have written Transaction with IsolationLevel.ReadUncommitted in my ADO.net Application using c# code

Whenever i run this application and try to select data from my Invoices table, i am not able to do so.

ex:
When i fire below query from my sql query window when ADO.net Application is running,
Below query works,
select * from Invoices with(nolock,nowait)

Below query does not work,
select * from invoices

I know that when we use with(nolock,nowait) we can read uncommitted data, but i want to read only committed data, but it seems that the transaction is putting lock on my table and not allowing me to read any data.

I want to read only committed data.

What I have tried:

I Tried IsolationLevel.ReadCommitted,IsolationLevel.ReadUnCommitted in my ado.net Application


Please suggest what can be done in this situation.

推荐答案

好的,所以SQL Server隔离级别的主题是一个非常棘手的问题。

现在专门解决你的问题,你的SELECT语句无法完成,因为它需要读取表中的所有记录,并且由于INSERT语句仍在插入记录,因此在插入完成之后,select无法完成读取表格。



现在让我们假设你很高兴您的SELECT语句忽略当前锁定的行(即插入的那些)。您可以使用READPAST查询提示,以便在Insert语句运行时允许您的select语句完成。



SELECT * FROM TableName WTIH(READPAST)

有意义吗?
OK, so the subject of SQL Server Isolation levels is quite a tricky one to get to grips with.
Now to address your question specifically, your SELECT statement cannot complete because it needs to read ALL records in the table and as the INSERT statement is still inserting records, the select cannot finish reading the table until after the insert completes.

Now let us suppose you are happy for your SELECT statement to ignore rows that are currently locked (i.e. those being inserted). You could use the READPAST query hint in order to permit your select statement to finish whilst the Insert statement is running.

SELECT * FROM TableName WTIH(READPAST)
Make sense?


这篇关于.net事务无法选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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