I wish to do some sort of delayed rollback (not in batch) in sample c# desktop app 1 button inserts the data, the other rolls it back
I tried the following but it is not working
error: The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConnectionString);
//conn = new SqlConnection(ConnectionString);
conn.Open();
try
{
//tran = conn.BeginTransaction("Transaction1");
SqlCommand cmd = new SqlCommand("begin transaction", conn);
SqlCommand cmd1 = new SqlCommand("insert into employee values ('6','aaaaaa','111')", conn);
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
conn.Close();
}
catch { }
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd2 = new SqlCommand("rollback transaction", conn);
cmd2.ExecuteNonQuery();
conn.Close();
}
Is what i am attempting even possible? or am I just going at it the wrong way?