private void btnConfigure_Click(object sender, EventArgs e)
{
try
{
dbConfigure dc = new dbConfigure();
SqlTransaction tr = conn.BeginTransaction();
cmd.Transaction = tr;
if (dc.configuration(cmd, ps.tableNames))
tr.Commit();
else
{
tr.Rollback();
mesg.show("Transaction is Rolled back");
}
}
catch (Exception ex)
{
mesg.show(ex.Message);
}
}
If i get problem anywhere in configuration method then it returns me false and I can see the message Transaction is Rolled Back. But actually transaction is not rolled back completely and some changes in database structure made by this function stay there inspite of rollback which is quite undesired. My Question is What can be the possibility of malfunctioning of Transaction roll back?
I have nowhere else any transaction in my project except the shared (above) method
Little Details
I am calling a very lengthy/complex function configuration of my class dbConfigure. It makes some required changes in database strucure. e.g. It
- Drops foriegnKeys
- Drops Primary keys
Drops auto-increment fields
It saves these keys before dropping and recreates in desired order/position
conn is an SqlConnection which is already opened, I use no connection anywhere other than this
cmd is conn.CreateCommand() I use no command anywhere other than this
I never close the connection in this whole process, however SqlDataReader's are closed in configuration function when they do their job.