Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:16:34+00:00 2026-05-26T12:16:34+00:00

I have a Visual Studio 2008 C# .NET 3.5 project using MySql 5.1.53 and

  • 0

I have a Visual Studio 2008 C# .NET 3.5 project using MySql 5.1.53 and MySql Connector/Net 6.4.4.

'protocol_version', '10'
'version', '5.1.53-community-log'
'version_comment', 'MySQL Community Server (GPL)'
'version_compile_machine', 'unknown'
'version_compile_os', 'Win64'

I create a table in my database like this.

using (MySqlConnection c = new MySqlConnection(connection_string))
{
    c.Open();
    using (MySqlCommand cmd = c.CreateCommand())
    using (MySqlTransaction xt = c.BeginTransaction())
    {
        cmd.Connection = c;
        cmd.Transaction = xt;
        try
        {
            cmd.CommandText =
                @"CREATE TABLE `my_table` (
                  ...
                ) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=latin1";
            cmd.ExecuteNonQuery();

            throw new System.Exception("This is a simulated failure!!!");

            xt.Commit();
        }
        catch
        {
            xt.Rollback();
            throw;
        }
    }
}

But, after the simulated failure the table still exists in my database.

What Do I need to do to make the transaction roll back correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:16:35+00:00Added an answer on May 26, 2026 at 12:16 pm

    Create Table statement causes automatic commit. It doesn’t participate in transaction.

    See Statements That Cause an Implicit Commit

    The statements listed in this section (and any synonyms for them)
    implicitly end a transaction, as if you had done a COMMIT before
    executing the statement.

    In your case you can just drop the table if an exception occurs. Its not technically a rollback but it should serve your purpose.

    Btw you don’t need a try catch block. Transaction is rolled back automatically if dispose is called on it without calling Commit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Visual Studio 2008 C# .NET 3.5 project using MySql 5.1.53 and
I have a Visual Studio 2008 C# .NET 3.5 project using MySql 5.1.53 and
I'm using Visual Studio 2008 . I have created a project with asp.net Mvc
I have C# .net project with SQL Server 2008 written in Visual Studio 2008.
I have a WPF VB.NET project in Visual Studio 2008. For some reason, Visual
I have a visual studio 2008 solution that includes an asp.net-hosted remoting project in
I have a C# .NET Compact Framework 3.5 mobile project in Visual Studio 2008.
We have an ASP.Net MVC 1.0 solution developed using Visual Studio 2008 and .net
I am using visual studio 2008 coding asp.net.vb I have 20 images on my
I have in Visual Studio 2008 a .NET 3.5 C# project that uses a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.