DO NOT BOTHER. THE PROBLEM IS NOT TRANSACTIONS. DUNNO HOW TO CLOSE / DELETE

Posted by matti on Stack Overflow See other posts from Stack Overflow or by matti
Published on 2010-04-21T17:18:03Z Indexed on 2010/04/21 20:33 UTC
Read the original article Hit count: 236

Filed under:
|
|
|
|

THE PROBLEM IS SOLVED. I DUNNO HOW TO CLOSE THIS QUESTION. ANOTHER SERVICE IS PROPABLY RUNNING AT ALMOST SAME SYNC THAT DOES THE THING. MY WORK "MATE" WILL HEAR A THING OR TWO IN THE MORNING.

I have following code in windows service: data is in the dataset and it has been populated earlier and then rows are updated and inserted to dataset tables before calling code below.

using (dataSetTxn = _cnctn.BeginTransaction())
{
    try
    {
        _somePlanAdptr.UpdateCommand.Transaction = dataSetTxn;
        _someLogAdptr.InsertCommand.Transaction = dataSetTxn;
        _someLinkAdptr.InsertCommand.Transaction = dataSetTxn;
        _someDataAdptr.InsertCommand.Transaction = dataSetTxn;

        _log.WriteDebug("Updating SomePlanAction");
        _somePlanAdptr.Update(_ofDataSet, "SomePlanAction");

        _log.WriteDebug(string.Format("Inserting {0} rows to SomeLog")); //error
        _someLogAdptr.Update(_ofDataSet, "SomeLog"); 

        _log.WriteDebug(string.Format("Updating SomeLink with {0} rows", _ofDataSet.Tables["SomeLink"].Rows.Count));
        _someLinkAdptr.Update(_ofDataSet, "SomeLink");

        _log.WriteDebug(string.Format("Updating SomeData with {0} rows", _ofDataSet.Tables["SomeData"].Rows.Count));
        _someDataAdptr.Update(_ofDataSet, "SomeData");

        _log.WriteDebug("Commiting all changes to database.");
        dataSetTxn.Commit();
    }
    catch (Exception e)
    {
        _log.WriteError("Updating database failed -> rollback", e);
        if (dataSetTxn != null && _cnctn.State == ConnectionState.Open)
            dataSetTxn.Rollback();

        throw e;
    }
}

so one of the lines causes an exception

log.WriteDebug(string.Format("Inserting {0} rows to SomeLog")); //error

still the first adapter's data is updated to database. when debugged the data is not yet updated until the method that calls all (including this bit) exits. The method that does all is timed with System.Threading.Timer.

Thanks & BR -Matti

© Stack Overflow or respective owner

Related posts about c#

Related posts about ADO.NET