c# - RollBack all executed query -
how can rollback executed query on 1 transaction in mysql query executed in c#
if (cn0.state != system.data.connectionstate.open) cn0.open(); cm0.connection = cn0; cm0.commandtext = "set autocommit=0 "; cm0.executenonquery(); cm0.commandtimeout = 0;//unlimited tr = cn0.begintransaction(system.data.isolationlevel.serializable); cm0.transaction = tr; try { cm0.commandtext = "create table if not exists i2019.produkh i2019.karyawanh "; cm0.executenonquery(); cm0.commandtext = "create table if not exists i2019.profileh i2019.karyawanh "; cm0.executenonquery(); cm0.commandtext = "create table if not exists i2019.customerh i2019.karyawanh "; cm0.executenonquery(); cm0.commandtext = "create table if not exists i2019.supplierh i2019.karyawanh "; cm0.executenonquery(); cm0.commandtext = "insert i2019.produkh (idx,idh,idb,faktur,tglb,jmlb,ket,edit,bf,modifat) " + "select idx, idh, idb, faktur, tglb, jmlb, ket, edit, bf, modifat karyawanh.t1 jmlb < 0"; cm0.executenonquery(); tr.commit(); if (cn0.state != system.data.connectionstate.closed) cn0.close(); tr.dispose(); } catch { tr.rollback(); if (cn0.state != system.data.connectionstate.closed) cn0.close(); tr.dispose(); throw; }
but error when execute query on create supplierh table rollback , closing connection.
and hope table :
- produkh
- profileh
- customerh
- supplierh
is not created, because there error on other
but after rolled supplierh table rolled , other not rolled back.
please tell me how?
Comments
Post a Comment