I have the following code (I'm new to .NET transactions) and it does seem to be executing at all. It's called through a webservice and is difficult for me to debug:
public void UpdateJailFiles(List<RMS.NameFile> names, RMS.Incident incident, int currentDate, int currentTime, int incidentKey)
{
String library = RMSLIBRARY;
IDbTransaction transaction;
using (IDbConnection conn = Connection)
{
conn.Open();
transaction = conn.BeginTransaction();
try
{
names.ForEach(nameFile =>
{
IDbCommand command = conn.CreateCommand();
command.CommandText = "call " + library + ".SP_NAMEFILE_UPDATE(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 0;
command.Transaction = transaction;
IDbDataParameter param = command.CreateParameter();
param.ParameterName = "@INCIDENTKEY";
param.DbType = DbType.Int32;
param.Value = nameFile.IncidentKey;
command.Parameters.Add(param);
///Many more params...
command.ExecuteNonQuery();
});
IDbCommand command2 = conn.CreateCommand();
command2.CommandText = "call " + library + ".SP_INCIDENTFILE_UPDATE(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
command2.CommandType = CommandType.StoredProcedure;
command2.Transaction = transaction;
IDbDataParameter param1b = command2.CreateParameter();
param1b.ParameterName = "@CASENUMBER";
param1b.DbType = DbType.String;
param1b.Value = incident.CaseNumber;
command2.Parameters.Add(param1b);
IDbDataParameter param2b = command2.CreateParameter();
param2b.ParameterName = "@INCIDENTFROMDATE";
param2b.DbType = DbType.Int32;
param2b.Value = incident.IncidentFromDate;
command2.Parameters.Add(param2b);
///Many more params...
command2.ExecuteNonQuery();
transaction.Commit();
} // end try
catch (Exception)
{
transaction.Rollback();
}
} // end using
}
See anything wrong with this code?