MySQL transaction problems have been debugged for half a day. Even tables of the MySQL database type MyISAM do not support transactions.

Source: Internet
Author: User

I have been debugging for half a day because l transaction is not effective today. It is because the MySQL database MyISAM type table does not support transactions.
Later, I changed the table type to InnoDB, and the transaction processing took effect. It was depressing for half a day !!!

 

Basic transaction code:

 

String sqlstr = @ "insert into 'mets _ daily_drinking_info '(patientid, cureid, drinkingtime, drinkingamount, drinkingamountunit)
Values ({0}, {1}, '{2}', {3}, {4 })";
Sqlstr = string. Format (sqlstr, 5555, 1, "13:06:44", "4ffff4444444", 4666 );
Mysqlconnection con = new mysqlconnection (mysqlconnstring. metsconnection );
Con. open (); // open the database connection before calling the Method
Mysqltransaction TRAN = con. begintransaction (); // You must enable the database connection before generating the sqltransaction object.
Try
{
Mysqlcommand comm = new mysqlcommand (); // create and declare a command object
Comm. Connection = con;
Comm. Transaction = Tran; // set the property to sqltransaction object.

Comm. commandtext = "delete from mets_daily_drinking_info"; // set

Comm. executenonquery (); // execute an SQL statement

Comm. commandtext = sqlstr; // set the SQL statement to be executed by the sqlcommand object

Comm. executenonquery (); // execute an SQL statement

Tran. Commit ();
}
Catch
{
Tran. rollback ();
Throw;
}
Finally
{
Con. Close (); // close the database connection
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.