c# - ADO.Net Transaction Not Working -


i have following code (i'm new .net transactions) , seem executing @ all. it's called through webservice , difficult me 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 wrong code?

your use of property (connection) load using statement suspect me. typically using used on new, local object instance so:

    using (idbconnection conn = new myconnectionclass())     {     } 

when exit using statement, idbconnection gets dispose() called on it, don't see anywhere property updated reflect status. want?

you may need dispose() idbcommand, it's not clear here - sqlcommand, that's true.

it helpful wrap whole code accesses db in try..except can diagnose and/or propagate db exception.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -