What I'm trying to achieve is: I'm calling stored procedures from 2 different databases. SP's have a simple insert entry in a table. There is no problem if both the transactions are successful, But when I tried to throw an exception in the 2nd DB SP the first one doesn't rollback. What am I doing wrong here?
C# Code:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
{
// Update DB1
using (SqlConnection con = new SqlConnection(connectionString1))
{
con.Open();
SqlCommand command1 = new SqlCommand("sp_1", con);
command1.ExecuteNonQuery();
// Update DB2
using (SqlConnection con2 = new SqlConnection(connectionString2))
{
con2.Open();
SqlCommand command2 = new SqlCommand("sp_2", con2);
command2.ExecuteNonQuery();
}
}
scope.Complete();
}
DB1 SP :
BEGIN
INSERT INTO TABLE_X1 VALUES(...)
END
DB2 SP :
BEGIN
THROW 51000, 'The record does not exist.', 1;
INSERT INTO TABLE_X2 VALUES(...)
END