title: MySql executing a MySqlScript even when the connection has been closed
body: <p>Is it possible for mysql to execute a script even when the connection has been closed?
  I am using mysql community server , through a .NET connector API. 
  Was using c# to test out the API.</p>
  
  <p>I have the following static class</p>
  
  <pre><code>using System;
  using System.Data;
  
  using MySql.Data;
  using MySql.Data.MySqlClient;
  
  public static class DataBase
  {
      static string connStr = "server=localhost;user=root;port=3306;password=*******;";
      static MySqlConnection conn;
  
      public static bool Connect()
      {        
          conn = new MySqlConnection(connStr);   
          try
          {            
              conn.Open();            
          }
          catch (Exception Ex)
          {
              ErrorHandler(Ex);
              return false;
          }
          return true;
      }
      public static int ExecuteScript(string scripttext) // returns the number of statements executed
      {
          MySqlCommand cmd = conn.CreateCommand();
          cmd.CommandText = scripttext;
          MySqlScript script;
          int count= 0;
  
          try
          {
              script = new MySqlScript(conn, cmd.CommandText);
  
              script.Error += new MySqlScriptErrorEventHandler(script_Error);
              script.ScriptCompleted += new EventHandler(script_ScriptCompleted);
              script.StatementExecuted += new MySqlStatementExecutedEventHandler(script_StatementExecuted);
              count = script.Execute();
          }
          catch (Exception Ex)
          {
              count = -1;
              ErrorHandler(Ex);            
          }
          return count;
      }
  
      # region EventHandlers
      static void script_StatementExecuted(object sender, MySqlScriptEventArgs args)
      {
          string Message = "script_StatementExecuted";
      }
  
      static void script_ScriptCompleted(object sender, EventArgs e)
      {
         string Message = "script_ScriptCompleted!";
      }
  
      static void script_Error(Object sender, MySqlScriptErrorEventArgs args)
      {
          string Message = "script_Error: " + args.Exception.ToString();
      }
      # endregion
      public static bool Disconnect()
      {
          try
          {
              conn.Close();
          }
          catch (Exception Ex)
          {
              ErrorHandler(Ex);
              return false;
          }
          return true;
      }
      public static void ErrorHandler(Exception Ex)
      {
          Console.WriteLine(Ex.Source);
          Console.WriteLine(Ex.Message);
          Console.WriteLine(Ex.ToString());
      }
  
  }
  </code></pre>
  
  <p>and I am using the following code to test out this class</p>
  
  <pre><code>using System;
  using System.Data;
  namespace Sample
  {
      public class Sample
      {
          public static void Main()
          {
              if (DataBase.Connect() == true)
                  Console.WriteLine("Connected");
  
              if (DataBase.Disconnect() == true)
                  Console.WriteLine("Disconnected");
  
              int count = DataBase.ExecuteScript("drop database sample");
              if (count != -1)
              {
                  Console.WriteLine(" Sample Script Executed");
                  Console.WriteLine(count);
              }
  
              Console.ReadKey();
  
          }
  
  
      }
  }
  </code></pre>
  
  <p>I noticed that even though I have closed my MySql connection using Disconnect() - which i have defined, mysql continues to execute the command i give next and no error is generated.</p>
  
  <p>I feel  like I am doing something wrong, as an error should be generated when i try to execute a script on a closed connection.</p>
  
  <p>Is it a problem in my code/logic or some flaw in mysql connector?</p>
  
  <p>I did check through the mysql workbench whether the command was executed properly and it was.</p>