I have a single method that reaches out to 2 methods. One handles Inserts and the other handles Updates. I put a transaction scope around these 2 methods so if there is any issues it will roll back. I notice that it is putting the data in the database but on error it is not removing it. I have tried RequiresNew and Required options for the scope but that doesn't seem to make a difference.
Additional Information: These stored procedures are actually stored in a "Utility" database which is holding the stored procedures but they are actually modifying records in a different database.
This method will insert approx 700+ records into 40 different tables.
Main Method
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
foreach (var change in changes)
{
switch (change.ChangeType)
{
case ChangeTypeEnum.Insert:
var result = DataAccess.InsertTableRow(sourceEnvironmentId, SuperClientVendorID,
DatabaseName, DataRouteName, change,
typeNamespace);
postList.Add(result);
break;
case ChangeTypeEnum.Update:
DataAccess.UpdateTableRow(sourceEnvironmentId, SuperClientVendorID, DatabaseName,
DataRouteName, change, typeNamespace);
postList.Add(change);
break;
}
}
scope.Complete();
}
Insert Method
var sproc = string.Format("Carma.usp_{0}_{1}_ins", databaseName, managedState.TypeName);
var connString = DataAccessManager.GetConnectionString(executionEnvironment, superClientVendorID, routeName, sproc, false);
using (var newConnection = new SqlConnection(connString))
{
newConnection.Open();
using (var newSqlCommand = new SqlCommand(sproc, newConnection))
{
newSqlCommand.CommandType = CommandType.StoredProcedure;
newSqlCommand.CommandTimeout = Setup.TimeOut;
newSqlCommand.Parameters.AddRange(GetParameters(managedState, typeNamespace, true));
newSqlCommand.ExecuteNonQuery();
return managedState;
}
}