Search code examples
mysql.netconnector

mysql .net - how to change SQL mode in mysql using .net connector


In MySQL Workbench, we have some SQL session modes like 'allow_invalid_dates','traditional', etc.

For example. set session sql_mode = 'allow_invalid_dates'

I am using .net connector for MySQL. so, how do i set these modes using that provider? is there any method for setting the SQL mode?


Solution

  • As mentioned in the comments, sending the query just like any other query will set the sqlmode for the curret session.

    using (MySqlConnection conn = new MySqlConnection(connectionstring))
    {
        conn.Open();
        using (MySqlCommand cmd = new MySqlCommand("set session sql_mode = 'allow_invalid_dates'", connection))
        {
            cmd.executeNonQuery();
        }
    
        //add here any query you want using the new sqlmode
    }