【发布时间】:2013-06-25 22:39:19
【问题描述】:
说明我的问题的最简单方法是使用以下 C# 代码:
using (SqlCommand cmd = new SqlCommand("SELECT * FROM [tbl]", connectionString))
{
using (SqlDataReader rdr = cmd.ExecuteReader())
{
//Somewhere at this point a concurrent thread,
//or another process changes the [tbl] table data
//Begin reading
while (rdr.Read())
{
//Process the data
}
}
}
那么在这种情况下rdr 中的数据会怎样呢?
【问题讨论】:
-
我假设你得到了旧数据。结果在查询执行时返回,并存储在客户端的网络缓冲区中,直到您使用 DataReader 的 Read 方法请求它们。但这取决于隔离级别。看看这个答案:stackoverflow.com/a/1539005/284240
-
@TimSchmelter:好的。感谢您的链接,尽管您自己的答案有些模棱两可。你说我会得到旧数据,但最后你说这取决于隔离级别。那么是哪一个呢?这个“隔离级别”是什么?
-
如果它是一个答案,我会编辑它并删除第一句话;-)
-
@ahmd0 我只是做了一些测试,然后我得到了旧数据——我运行
select *时得到的数据 -
@Aristos:谢谢。那么 Tim 提出的 SQL Server 隔离级别呢?
标签: c# asp.net .net database concurrency