Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 27, 2018 05:57
Show Gist options
  • Save talkingdotnet/d050970162908fe45e103a2d954cb972 to your computer and use it in GitHub Desktop.
Save talkingdotnet/d050970162908fe45e103a2d954cb972 to your computer and use it in GitHub Desktop.
private void DisableForeignKey(bool flag)
{
string query = "";
if (flag)
query = "SET FOREIGN_KEY_CHECKS=0;";
else
query = "SET FOREIGN_KEY_CHECKS=1;";
try
{
using (MySqlConnection connection = new MySqlConnection(_connectionString))
{
using (MySqlCommand command = new MySqlCommand())
{
connection.Open();
command.Connection = connection;
command.CommandText = query;
command.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
WriteToConsole("Error: DisableForeignKey()" + "\n" + ex.ToString());
throw ex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment