Note that there are some explanatory texts on larger screens.

plurals
  1. POASP MVC 4 MySQL, trouble handling transaction error
    primarykey
    data
    text
    <p>My Environment/Application: Ubuntu(x64) Mono xsp4 mysql(strict_all_tables on) ASP.NET MVC4 Elmah</p> <p>I'm trying to use ADO.NET and wrap my requests in a transaction. I have a table with one column that is datatype integer. I try inserting 2 integers and then an invalid datatype. My goal is to get the transaction to rollback when it tries to insert the invalid data. mysql server is throwing the error when trying to execute the sql command from MySQL Workbench.</p> <p>I set a breakpoint on the commit, rollback, and close lines of code. The commit line is hit, ten the close line is hit. However the server does return a 500 error(YSOD) with the sql exception, but my exception handling does not trap an error and rollback the transaction.</p> <pre><code>public class BaseController : Controller { private MySqlConnection _connection; private MySqlTransaction _transaction; protected override void OnActionExecuting (ActionExecutingContext filterContext) { _connection = new MySqlConnection (ConfigurationManager.ConnectionStrings["myconnstringname"].ConnectionString); _connection.Open (); _transaction = _connection.BeginTransaction (); base.OnActionExecuting (filterContext); } protected override void OnActionExecuted (ActionExecutedContext filterContext) { try { _transaction.Commit (); } catch(Exception ex) { _transaction.Rollback(); throw ex; } finally { _connection.Close (); } base.OnActionExecuted (filterContext); } protected MySqlCommand GetCommand(string commandText) { return new MySqlCommand (commandText, _connection, _transaction); } } public class HomeController : BaseController { public ActionResult Index () { var cmd = GetCommand ("insert into testing select 1;"); cmd.ExecuteNonQuery (); cmd = GetCommand ("insert into testing select 2;"); cmd.ExecuteNonQuery (); cmd = GetCommand ("insert into testing select 'grgregre';"); cmd.ExecuteNonQuery (); return Content (""); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload