This SqlTransaction has completed; it is no longer usable
-
Currently i m using asp.net 2.0 with sql server 2000 database..
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx");
}
catch
{
trans.Rollback();
throw;
}while executing the above coding all executing correctly but at the time of
response.redirect
, its throwing the error.. help me. -Karan
-
Currently i m using asp.net 2.0 with sql server 2000 database..
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx");
}
catch
{
trans.Rollback();
throw;
}while executing the above coding all executing correctly but at the time of
response.redirect
, its throwing the error.. help me. -Karan
what actually the error is?? Ithink You Write it InCorrectly You Write Response.Redirect("~/NewInc.aspx");
-
what actually the error is?? Ithink You Write it InCorrectly You Write Response.Redirect("~/NewInc.aspx");
-
the error is : This SqlTransaction has completed; it is no longer usable and its a simple redirect page command.. but its getting error at that page.. but all executions are happening perfectly. but its not getting redirected..... guide me plz - Karan
Have you tried moving the redirect outside the try/catch ?
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.
-
Currently i m using asp.net 2.0 with sql server 2000 database..
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx");
}
catch
{
trans.Rollback();
throw;
}while executing the above coding all executing correctly but at the time of
response.redirect
, its throwing the error.. help me. -Karan
Are you talking about ThreadAbortException... Both Response.Redirect and Server.Transfer creates a new Thread and terminates the Current Thread by calling Thread.Abort and redirects the Response stream to new thread. Thus It generates a First chance ThreadAbortException. If you call Response.Redirect(url,false) it will not throw the first chance exception as it will skip the call to Response.End in the current thread. so your code should be
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx", false);
}
catch
{
trans.Rollback();
throw;
}I hope this help you. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Are you talking about ThreadAbortException... Both Response.Redirect and Server.Transfer creates a new Thread and terminates the Current Thread by calling Thread.Abort and redirects the Response stream to new thread. Thus It generates a First chance ThreadAbortException. If you call Response.Redirect(url,false) it will not throw the first chance exception as it will skip the call to Response.End in the current thread. so your code should be
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx", false);
}
catch
{
trans.Rollback();
throw;
}I hope this help you. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Currently i m using asp.net 2.0 with sql server 2000 database..
SqlTransaction trans = null;
try
{
trans = conn.BeginTransaction();
sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
sqlCmd.Transaction = trans;
sqlCmd.ExecuteNonQuery();
sqlCmd.Dispose();
trans.Commit();
Response.Redirect("NewInc.aspx");
}
catch
{
trans.Rollback();
throw;
}while executing the above coding all executing correctly but at the time of
response.redirect
, its throwing the error.. help me. -Karan