0

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.

tzvis
  • 41
  • 4
  • Sounds like something in your query is making the ODBC driver to crash. Either it's a bug and/or there's something not quite right in the query. People might be able to give you some more insight if you can share the query that makes it crash. – Martin Costello Aug 07 '20 at 20:00
  • Check your connection string. In case you need to handle such exception - this is the way https://stackoverflow.com/a/62843347/1704458 – T.S. Aug 07 '20 at 20:19
  • @MartinCostello it crashes on any query. Here is the connectionString "Driver={MariaDB ODBC 3.1 Driver};TCPIP=1;Server=127.0.0.1Database=mysql;Uid=root;Pwd=admin;Port=3306" – tzvis Aug 07 '20 at 22:00
  • 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. – tzvis Aug 10 '20 at 12:46

1 Answers1

1

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
tzvis
  • 41
  • 4