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

AccessViolation in OdbcDataReader.GetOrdinal(string name) if I call stored procedure

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Windows 7 Pro, x64, MariaDB ODBC Driver 0.9.1, Microsoft Visual Studio 2012, NET Framework 4.5

    Description

      I'm getting AccessViolation error when I'm trying to get the fields position with OdbcDataReader.GetOrdinal(string method) if result set is generated by stored procedure. With plain SELECT statements everything is ok.

      The exception stack trace and failing code is below.

      – Exception –

      System.AccessViolationException was unhandled
      HResult=-2147467261
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      Source=System.Data
      StackTrace:
      at System.Data.Common.UnsafeNativeMethods.SQLColAttributeW(OdbcStatementHandle StatementHandle, Int16 ColumnNumber, Int16 FieldIdentifier, CNativeBuffer CharacterAttribute, Int16 BufferLength, Int16& StringLength, IntPtr& NumericAttribute)
      at System.Data.Odbc.OdbcDataReader.GetColAttributeStr(Int32 i, SQL_DESC v3FieldId, SQL_COLUMN v2FieldId, HANDLER handler)
      at System.Data.Odbc.OdbcDataReader.GetName(Int32 i)
      at System.Data.ProviderBase.FieldNameLookup..ctor(IDataRecord reader, Int32 defaultLocaleID)
      at System.Data.Odbc.OdbcDataReader.GetOrdinal(String value)
      at MariaDbOdbcConnectorTest1.Program.TestGetOrdinalWithStoredProcedure() in d:\Work\Project1\Troubleshooting\MariaDbOdbcConnector\MariaDbOdbcConnectorTest1\MariaDbOdbcConnectorTest1\Program.cs:line 94
      at MariaDbOdbcConnectorTest1.Program.Main(String[] args) in d:\Work\Project1\Troubleshooting\MariaDbOdbcConnector\MariaDbOdbcConnectorTest1\MariaDbOdbcConnectorTest1\Program.cs:line 17
      at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

      – Failing Code –

      public static void TestGetOrdinalWithStoredProcedure()
      {
      Console.WriteLine("_ODBC_0.9.1 test#2__");
      using (IDbConnection connection = new OdbcConnection())
      {
      connection.ConnectionString = "DSN=MariaDB10";
      connection.Open();

      using (IDbCommand command = connection.CreateCommand())

      { command.CommandType = CommandType.Text; command.CommandText = "DROP PROCEDURE IF EXISTS test1"; command.ExecuteNonQuery(); command.CommandText = @" CREATE PROCEDURE test1() BEGIN SELECT 1 AS A; END; "; command.ExecuteNonQuery(); }

      using (IDbCommand command = connection.CreateCommand())
      {
      command.CommandType = CommandType.StoredProcedure;
      command.CommandText = "CALL test1";
      using (IDataReader reader = command.ExecuteReader())
      {
      while (reader.Read())
      {

      int position = reader.GetOrdinal("A"); // This fails
      Console.WriteLine("

      {0}", reader.GetInt32(position));
      // Console.WriteLine("{0}

      ", reader.GetInt32(0)); // This works fine
      }
      }
      }
      }
      }

      – Working Code –

      public static void TestGetOrdinal()
      {
      Console.WriteLine("_ODBC_0.9.1 test#1__");
      using (IDbConnection connection = new OdbcConnection())
      {
      connection.ConnectionString = "DSN=MariaDB10";
      connection.Open();
      using (IDbCommand command = connection.CreateCommand())
      {
      command.CommandType = CommandType.Text;
      command.CommandText = "SELECT 1 AS A";
      using (IDataReader reader = command.ExecuteReader())
      {
      while (reader.Read())
      {
      int position = reader.GetOrdinal("A"); // works fine
      Console.WriteLine("

      {0}

      ", reader.GetInt32(position));
      }
      }
      }
      }
      }

      Attachments

        Activity

          People

            georg Georg Richter
            andrey.lartsev Andrey Lartsev
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.