1

I am writing a Windows Forms application that needs to query 2 fields from a MAS-90 database. For this we use the MAS 90 32-bit ODBC Driver by ProvideX called SOTAMAS90. Here is the code I use to retrieve a DataTable from the MAS-90 database.

public static DataTable getDatatable(string qry)
{
    DataTable dt = new DataTable();            

     using (OdbcConnection conn = new OdbcConnection(GetSQLConnection()))
     {
         try
         {
             OdbcCommand cmd = new OdbcCommand(qry, conn);
             cmd.CommandType = CommandType.Text;
             conn.Open();
             OdbcDataAdapter adpt = new OdbcDataAdapter(cmd);

             adpt.Fill(dt);

             cmd.Dispose();
             conn.Close();
             conn.Dispose();
        }
        catch (OdbcException e) { conn.Close(); }
        catch (AccessViolationException ae) { conn.Close(); }
        catch (UnauthorizedAccessException ue) { conn.Close(); }                    
    }

    return dt;
}

On line adpt.Fill(dt) I get the following exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This was working just fine yesterday. Today Visual Studio is telling me that this is an Unhandled AccessViolationException even though you can clearly see the try/catches. I had to add <legacyCorruptedStateExceptionsPolicy enabled="true"/> to my config file just for the exception to be caught in the try/catch.

The other strange thing is I am able to connect to the database and run the same exact query (which is just selecting 2 fields from a table) using the ODBC Query Tool by Jaime De Los Hoyos M. (Available here)

Any help at resolving this issue is greatly appreciated. Please let me know if you need additional information.

I also wanted to add that I have tried:

  • Targeting x86 in my app as the Driver is 32-bit
  • Giving permissions to the directory where the database is stored
  • Restarting PC
  • Changing query to add parameters with cmd.Parameters.AddWithValue("@PARAM", "Value")
Community
  • 1
  • 1

1 Answers1

1

I was able to resolve my issue. The database was stored on a server to which my PC had a mapped drive to. For whatever reason, the mapping broke for the MAS 90 32-bit ODBC Driver. This was strange because I was still able to access the network drive's files via File Explorer and I was also able to query the table via the ODBC query tool I mentioned (which uses the same ODBC driver). I discovered this when I wanted to change the Database Directory field (seen below) and it kept telling me the path was invalid or inaccessible (even though it was accessing it for the ODBC query tool).

Anyway, I remapped the network drive, then deleted and recreated the SOTAMAS90 DSN and it worked again.

ODBC Driver Configuration