G
Guest
What is desried, during a transaction, with its IsolationLevel set to
RepeatableRead, will it block out other transactions from performing a read
or write to the same record until it's transaction has completed?
See code snippet below:
SqlConnection connection = new SqlConnection(connectionString))
connection.Open();
SqlCommand command = connection.CreateCommand();
SqlTransaction transaction;
// Will this block another transaction from reading/writing same record?
transaction = connection.BeginTransaction(IsolationLevel.RepeatableRead);
command.Connection = connection;
command.Transaction = transaction;
command.CommandText ="SELECT MyTable.OpenForEdit FROM MyTable WHERE
KeyIndex=0";
SqlDataReader reader = command.ExecuteReader();
bool openForEdit = reader.GetBoolean(0);
if (openForEdit == false)
{
command.CommandText = "UPDATE MyTable SET OpenForEdit=1 WHERE
KeyIndex=0;"; // Set OpenForEdit to 1
command.ExecuteNonQuery();
}
transaction.Commit();
// Reset Isolation Level to default
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
transaction.Commit();
RepeatableRead, will it block out other transactions from performing a read
or write to the same record until it's transaction has completed?
See code snippet below:
SqlConnection connection = new SqlConnection(connectionString))
connection.Open();
SqlCommand command = connection.CreateCommand();
SqlTransaction transaction;
// Will this block another transaction from reading/writing same record?
transaction = connection.BeginTransaction(IsolationLevel.RepeatableRead);
command.Connection = connection;
command.Transaction = transaction;
command.CommandText ="SELECT MyTable.OpenForEdit FROM MyTable WHERE
KeyIndex=0";
SqlDataReader reader = command.ExecuteReader();
bool openForEdit = reader.GetBoolean(0);
if (openForEdit == false)
{
command.CommandText = "UPDATE MyTable SET OpenForEdit=1 WHERE
KeyIndex=0;"; // Set OpenForEdit to 1
command.ExecuteNonQuery();
}
transaction.Commit();
// Reset Isolation Level to default
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
transaction.Commit();