Created
April 19, 2017 09:14
-
-
Save EgorBo/8db4ae87c6982f7a320feedc0f9534ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.SqlClient; | |
namespace ConsoleApp1 | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var cs = @"Server=EGORBO\SQLEXPRESS;Database=testo;User Id=sa;Password=qwerty123;"; | |
using (var connection1 = new SqlConnection(cs)) | |
{ | |
connection1.Open(); | |
using (var connection2 = new SqlConnection(cs)) | |
{ | |
connection2.Open(); | |
Exec(connection2, "BEGIN TRANSACTION;"); | |
Exec(connection2, "UPDATE Table_1 SET FOO = 2;"); | |
connection2.Close(); | |
} | |
//it won't execute, Table_1 is locked | |
Exec(connection1, "UPDATE Table_1 SET FOO=3;"); | |
} | |
} | |
private static void Exec(SqlConnection c, string s) | |
{ | |
using (var m = c.CreateCommand()) | |
{ | |
m.CommandText = s; | |
m.ExecuteNonQuery(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment