I am Using Transaction Scope
for Performing the Insert In Multiple Tables using Try and Catch
. But when i am Getting the Error Within Transaction Scope
it's not allowing me to Save the Data in catch
also.
My Code
using (var transaction = new TransactionScope())
{
try
{
//Insert in Table1
//Insert in Table2
//Insert in Table3
transaction.Complete();
transaction.Dispose();
}
catch(Exception ex)
{
transaction.Dispose();
//Insert in ErrorHandlerTable (Independent Table)
}
}
Now The Problem is whenever i am getting the error in try
block for foreign key constraints
i am unable to insert into ErrorHandlerTable (Independent Table). Always Getting Following Exception
:
{"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_Table1_PkId\". The conflict occurred in database \"MyTransactionDatabase\", table \"dbo.Table2\", column 'PkId'.\r\nThe statement has been terminated."}
Can anyone help in this?