Transactions in MySql used in Vb.net
Transactions are very important topic in the Mysql. let us suppose we are working with the Mysql database that is auto commit mode is true. but in all scenarios auto commit mode true will be not safe in that situvations we can turn off MySql database into different modes either Auto commit mode is true or Auto commit mode is false with out effect to whole application.
While we apply transactions that are applied to that transaction block only. If we want to implement transactions we need to start the transaction and wrote the desired code.
This function is used to start the transaction and set the database to auto commit to false
Public Sub SetTransactionForAccounts()
cmdtext = “START transaction;”
connection.ExecuteOperation(cmdtext)
cmdtext = “SET autocommit=0;”
connection.ExecuteOperation(cmdtext)
connection.ExecuteOperation(cmdtext)
End Sub
This function is used to Commit the changes done
Public Sub SetCommit()
cmdtext = “commit;”
connection.ExecuteOperation(cmdtext)
End Sub
This function is used to commit the transaction and set the database to auto commit to true
Public Sub setAccountsCommit()
cmdtext = “commit;”
connection.ExecuteOperation(cmdtext)
cmdtext = “set autocommit=1;”
connection.ExecuteOperation(cmdtext)
End Sub
This function is used to roll back the changes and set the database to auto commit to true
Public Sub setAccountsRollBack()
cmdtext = “Rollback;”
connection.ExecuteOperation(cmdtext)
cmdtext = “set autocommit=1;”
connection.ExecuteOperation(cmdtext)
End Sub
This function is used to roll back the changes
Public Function setRollBack() As Boolean
cmdtext = “Rollback;”
Return connection.ExecuteOperation(cmdtext)
End Function

