我有一个非常慢的 sql 事务,它在表中插入新行。来自其他连接的所有其他“选择”查询等待此事务解锁表。
是否可以在第一个事务有效时从表中获取旧行?
SqlExpress 2008 R2。例如:
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(
delegate()
{
var conn = new SqlConnection(@"Data Source=ARTNB\SQLEXPRESS;Initial Catalog=test;User ID=**;Password=******");
conn.Open();
var cmd = conn.CreateCommand();
var tr = conn.BeginTransaction( IsolationLevel.RepeatableRead, "test");
cmd.Transaction = tr;
cmd.CommandText = @"INSERT INTO Cards (SerialNumber,OperationID,TariffID,RequestTime,State,AgentInfo) VALUES('1213','345',13, GETDATE(),1,'')";
cmd.ExecuteNonQuery();
//very slow transaction
System.Threading.Thread.Sleep(300000);
tr.Commit();
conn.Close();
});
t.Start();
}
private void button2_Click(object sender, EventArgs e)
{
var conn = new SqlConnection(@"Data Source=ARTNB\SQLEXPRESS;Initial Catalog=test;User ID=**;Password=******");
conn.Open();
var cmd = conn.CreateCommand();
var tr = conn.BeginTransaction(IsolationLevel.RepeatableRead, "test2");
cmd.Transaction = tr;
cmd.CommandText = @"SELECT COUNT(*) FROM Cards";
var r = cmd.ExecuteReader();
r.Read();
r.Close();
tr.Commit();
conn.Close();
}
button2_Click 方法不会立即获取一行,它等待提交我有一个非常慢的 sql 事务,它在表中插入新行。来自其他连接的所有其他“选择”查询等待此事务解锁表。
是否可以在第一个事务有效时从表中获取旧行?
SqlExpress 2008 R2。例如:
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(
delegate()
{
var conn = new SqlConnection(@"Data Source=ARTNB\SQLEXPRESS;Initial Catalog=test;User ID=**;Password=******");
conn.Open();
var cmd = conn.CreateCommand();
var tr = conn.BeginTransaction( IsolationLevel.RepeatableRead, "test");
cmd.Transaction = tr;
cmd.CommandText = @"INSERT INTO Cards (SerialNumber,OperationID,TariffID,RequestTime,State,AgentInfo) VALUES('1213','345',13, GETDATE(),1,'')";
cmd.ExecuteNonQuery();
//very slow transaction
System.Threading.Thread.Sleep(300000);
tr.Commit();
conn.Close();
});
t.Start();
}
private void button2_Click(object sender, EventArgs e)
{
var conn = new SqlConnection(@"Data Source=ARTNB\SQLEXPRESS;Initial Catalog=test;User ID=**;Password=******");
conn.Open();
var cmd = conn.CreateCommand();
var tr = conn.BeginTransaction(IsolationLevel.RepeatableRead, "test2");
cmd.Transaction = tr;
cmd.CommandText = @"SELECT COUNT(*) FROM Cards";
var r = cmd.ExecuteReader();
r.Read();
r.Close();
tr.Commit();
conn.Close();
}
button2_Click 方法不会立即获取一行,它会在 button1_Click 线程中等待提交。