i have referred this perform rollback operation in wpf c# application. code tried follows:
using (odbcconnection connection = new odbcconnection("connectionstring")) { odbccommand command = new odbccommand(); odbctransaction transaction = null; command.connection = connection; try { connection.open(); transaction = connection.begintransaction(); command.connection = connection; command.transaction = transaction; command.commandtext = "insert tablea (a, b, c) values (10,10,10)"; command.executenonquery(); command.commandtext = "nsert tableb (d,e,f) values (20,20,20)"; command.executenonquery(); transaction.commit(); } catch(exception ex) { console.writeline(ex.message); try { transaction.rollback(); } catch { } }
intentionally second query has been made wrong. intention when enter catch block on calling transaction.rollback() values added due executing of first query in tablea not reflected since rollback called. not case values not rolledback , present in tablea. have searched various resources online no luck. cannot use sqlconnection instead of odbcconnection application not support that. there work around or alternative method can achieve have in mind. please me out.
you have msdn example. had once problem odbc , issue odbc vendor drivers. recommend check possibility.
Comments
Post a Comment