tzvis
tzvis

Reputation: 41

'System.AccessViolationException' when switching from mysql/sql client to ODBC client in C#

I have c# code that is taking arguments from an xml file and executing commands from a .sql file passed in to the xml.

I have a case statement for different types of connections.

switch (type)
{
    case @"type=mysql":
        conn = new MySqlConnection(connection);
        break;

    case @"type=odbc":
        conn = new OdbcConnection(connection);
        break;

}

When I run using a mySql or sql client it works fine:

MySqlCommand queryCmd = new MySqlCommand(query, con);
queryCmd.ExecuteNonQuery();

but when I switch to an odbc client

OdbcCommand queryCmd = new OdbcCommand(query, con);
queryCmd.ExecuteNonQuery();

I get

"Exception thrown: read access violation. stmt was nullptr." And "System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'"

update: : I tested with a sql server connection and this does execute properly. It fails when using with a MariaDb connection. Also this fails on the execution, not on the connection.

Upvotes: 0

Views: 605

Answers (1)

tzvis
tzvis

Reputation: 41

What ended up working for me:

  • check the option to enable multiple statements in the Data Source configuration
  • Add "OPTIONS=92344352" to the connection string

Upvotes: 1

Related Questions