Uploaded image for project: 'MariaDB Connector/ODBC'
  1. MariaDB Connector/ODBC
  2. ODBC-429

AccessViolationException when executing a SELECT on a non existing table

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 3.2.2
    • 3.2.3
    • General
    • None
    • Windows x64, .NET 8.0

    Description

      When executing the following code:

      using System.Data.Odbc;
       
      string connString = "Driver={MariaDB ODBC 3.2 Driver};Server=localhost;Port=3307;Database=DataFlow;User=root;Password=etlboxpassword;SSL Mode=None;";
       
      try {
          var dbConnection = new OdbcConnection(connString);
          dbConnection.Open();
          var command = dbConnection.CreateCommand();
          command.CommandText = $"SELECT * FROM non_existing_table";
          command.CommandTimeout = 60;
          var reader = command.ExecuteReader();
      } catch {
          Console.WriteLine("Error occured");
      }
      

      a critical `System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'` exception is thrown, and the program execution is aborted (without going into the catch-block).

      A "normal" System.Data.Odbc.OdbcException would be expected. The access violation is not thrown when the try/catch is removed.

      Sample project is attached.

      Attachments

        Issue Links

          Activity

            Lawrin Lawrin Novitsky added a comment - - edited

            Thank you for your report. What is interesting, is that we do have test doing select from non-existent table and all is fine with it.
            Interesting what makes your test different.

            Lawrin Lawrin Novitsky added a comment - - edited Thank you for your report. What is interesting, is that we do have test doing select from non-existent table and all is fine with it. Interesting what makes your test different.
            andreas.lennartz Andreas Lennartz added a comment - - edited

            Hi Lawrin,
            thanks for getting back to me.
            I observed the following behaviour.

            When I run this using a debugger attached:

                var dbConnection = new OdbcConnection(connString);
                dbConnection.Open();
                var command = dbConnection.CreateCommand();
                command.CommandText = $"SELECT * FROM non_existing_table";
                command.CommandTimeout = 60;
                var reader = command.ExecuteReader();
            

            I get a ERROR [42S02] [ma-3.2.2][11.4.2-MariaDB-ubu2404]Table 'DataFlow.non_existing_table' doesn't exist' exception, which is the expected one.

            But when I run this with a debugger:

            try {
                var dbConnection = new OdbcConnection(connString);
                dbConnection.Open();
                var command = dbConnection.CreateCommand();
                command.CommandText = $"SELECT * FROM non_existing_table";
                command.CommandTimeout = 60;
                var reader = command.ExecuteReader();
            } catch {
                throw;
            }
            

            I get the 'System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' exception. (Which is a "hard" exception, which will stop the execution of the .NET code immediately, without entering the catch block)

            So, there seems to be a difference when running the code with or without a try/catch statement.

            This error popped up in my test environment when upgrading to 11.4. I never had issues with this when using the previous MariaDb versions (10.X).

            andreas.lennartz Andreas Lennartz added a comment - - edited Hi Lawrin, thanks for getting back to me. I observed the following behaviour. When I run this using a debugger attached: var dbConnection = new OdbcConnection(connString); dbConnection.Open(); var command = dbConnection.CreateCommand(); command.CommandText = $ "SELECT * FROM non_existing_table" ; command.CommandTimeout = 60 ; var reader = command.ExecuteReader(); I get a ERROR [42S02] [ma-3.2.2] [11.4.2-MariaDB-ubu2404] Table 'DataFlow.non_existing_table' doesn't exist' exception, which is the expected one. But when I run this with a debugger: try { var dbConnection = new OdbcConnection(connString); dbConnection.Open(); var command = dbConnection.CreateCommand(); command.CommandText = $ "SELECT * FROM non_existing_table" ; command.CommandTimeout = 60 ; var reader = command.ExecuteReader(); } catch { throw ; } I get the 'System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' exception. (Which is a "hard" exception, which will stop the execution of the .NET code immediately, without entering the catch block) So, there seems to be a difference when running the code with or without a try/catch statement. This error popped up in my test environment when upgrading to 11.4. I never had issues with this when using the previous MariaDb versions (10.X).

            Those are looks to be the same issue

            Lawrin Lawrin Novitsky added a comment - Those are looks to be the same issue

            For some reason .Net still calls SQLMoreResults on the handle where query resulted in error. The driver crashed on that. The fix and the testcase have been pushed

            Lawrin Lawrin Novitsky added a comment - For some reason .Net still calls SQLMoreResults on the handle where query resulted in error. The driver crashed on that. The fix and the testcase have been pushed

            People

              Lawrin Lawrin Novitsky
              andreas.lennartz Andreas Lennartz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.