Transaction problem in asp.net
-
Hi, I am am using commit and rollback transaction in asp.net. due to some reasons transaction is not working.In the following code i am deleting the record and then inserting new record.If the transaction fails the transaction will be rollback.but it is not rolling back the transaction. The following is the code:-
public static void insertdata()
{
string strfilename = "~\\Documents\\" + ViewState["MissionCat"];
string strexcelConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + "; Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"";
string strsqlConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();using (OleDbConnection connection = new OleDbConnection(strexcelConnectionString)) { connection.Open(); OleDbCommand command = new OleDbCommand("Select \[Mission\] ,\[Civilian\] ,\[Military\] ,\[Police\],\[Unknown\] ,\[Non-UN\] ,\[Total\] FROM \[Sheet1$\]", connection); //truncate the table before inserting new data. SqlConnection cnntrunc = new SqlConnection(strsqlConnectionString); //open the connection. cnntrunc.Open(); //begin the transaction. SqlTransaction myTrans = cnntrunc.BeginTransaction(); //New a transaction SqlCommand truntble = new SqlCommand(); truntble.Transaction = myTrans; truntble.Connection = cnntrunc; try { //Create DbDataReader to Data Worksheet. using (DbDataReader dr = command.ExecuteReader()) { truntble.CommandText = "DELETE FROM MissionCatReport"; truntble.ExecuteNonQuery(); //commit the transaction. myTrans.Commit(); //Bulk Copy to SQL Server. using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strsqlConnectionString)) { bulkCopy.DestinationTableName = "MissionCatReport"; bulkCopy.WriteToServer(dr); } } } catch (OleDbException ex) { myTrans.Rollback(); throw ex; } catch (Inv
-
Hi, I am am using commit and rollback transaction in asp.net. due to some reasons transaction is not working.In the following code i am deleting the record and then inserting new record.If the transaction fails the transaction will be rollback.but it is not rolling back the transaction. The following is the code:-
public static void insertdata()
{
string strfilename = "~\\Documents\\" + ViewState["MissionCat"];
string strexcelConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + "; Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"";
string strsqlConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();using (OleDbConnection connection = new OleDbConnection(strexcelConnectionString)) { connection.Open(); OleDbCommand command = new OleDbCommand("Select \[Mission\] ,\[Civilian\] ,\[Military\] ,\[Police\],\[Unknown\] ,\[Non-UN\] ,\[Total\] FROM \[Sheet1$\]", connection); //truncate the table before inserting new data. SqlConnection cnntrunc = new SqlConnection(strsqlConnectionString); //open the connection. cnntrunc.Open(); //begin the transaction. SqlTransaction myTrans = cnntrunc.BeginTransaction(); //New a transaction SqlCommand truntble = new SqlCommand(); truntble.Transaction = myTrans; truntble.Connection = cnntrunc; try { //Create DbDataReader to Data Worksheet. using (DbDataReader dr = command.ExecuteReader()) { truntble.CommandText = "DELETE FROM MissionCatReport"; truntble.ExecuteNonQuery(); //commit the transaction. myTrans.Commit(); //Bulk Copy to SQL Server. using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strsqlConnectionString)) { bulkCopy.DestinationTableName = "MissionCatReport"; bulkCopy.WriteToServer(dr); } } } catch (OleDbException ex) { myTrans.Rollback(); throw ex; } catch (Inv
is it throwing any error message... how do you say that it is not working.....
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
Hi, I am am using commit and rollback transaction in asp.net. due to some reasons transaction is not working.In the following code i am deleting the record and then inserting new record.If the transaction fails the transaction will be rollback.but it is not rolling back the transaction. The following is the code:-
public static void insertdata()
{
string strfilename = "~\\Documents\\" + ViewState["MissionCat"];
string strexcelConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strfilename) + "; Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"";
string strsqlConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();using (OleDbConnection connection = new OleDbConnection(strexcelConnectionString)) { connection.Open(); OleDbCommand command = new OleDbCommand("Select \[Mission\] ,\[Civilian\] ,\[Military\] ,\[Police\],\[Unknown\] ,\[Non-UN\] ,\[Total\] FROM \[Sheet1$\]", connection); //truncate the table before inserting new data. SqlConnection cnntrunc = new SqlConnection(strsqlConnectionString); //open the connection. cnntrunc.Open(); //begin the transaction. SqlTransaction myTrans = cnntrunc.BeginTransaction(); //New a transaction SqlCommand truntble = new SqlCommand(); truntble.Transaction = myTrans; truntble.Connection = cnntrunc; try { //Create DbDataReader to Data Worksheet. using (DbDataReader dr = command.ExecuteReader()) { truntble.CommandText = "DELETE FROM MissionCatReport"; truntble.ExecuteNonQuery(); //commit the transaction. myTrans.Commit(); //Bulk Copy to SQL Server. using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strsqlConnectionString)) { bulkCopy.DestinationTableName = "MissionCatReport"; bulkCopy.WriteToServer(dr); } } } catch (OleDbException ex) { myTrans.Rollback(); throw ex; } catch (Inv
I don't see any code to commit the transaction ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.