dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlDump Class
Members Example

In This Topic
    MySqlDump Class
    In This Topic
    Serves to store a database or its parts as a script and to restore database from the generated script.
    Syntax
    'Declaration
     
    Public NotInheritable Class MySqlDump 
       Inherits Devart.Common.DbDump
       Implements System.ComponentModel.IComponentSystem.IDisposable 
    Remarks
    MySqlDump by its behaviour is similar to mysqldump program.

    Use Tables property to specify a list of tables to be stored. If Tables property is an empty string all tables will be included into the dump text. To generate a script call Backup method. Result script can be viewed in DumpText. To run it on a database, use Restore method.

    When generating scripts, all operations are executed within database that MySqlConnection.Database property of associated MySqlConnection object references to. When restoring tables using the generated script, the property MySqlConnection.Database is used only if IncludeDatabase has been set to false in the moment of script generation.

    If the MySqlConnection.Unicode is true, MySqlDump uses UTF8, otherwise it uses default encoding.

    Note: This class is not available in .NET Standard 1.3 compatible assembly. It is available only in the assembly for full .NET Framework and .NET Standard 2.0 compatible assembly.

    Note: This class is available with dotConnect for MySQL Professional edition only.

    Example
    The following example creates a MySqlDump component and executes backup of the specified tables using Backup method. After execution of backup operation the result is saved at d:\tmp\mysqldump.dmp file. The second routine executes the generated script using Restore method.
    public void DumpIt(MySqlConnection myConnection)
    {
      myConnection.Open();
      MySqlDump mySqlDump = new MySqlDump();
      mySqlDump.Connection = myConnection;
      myConnection.Database = "Test";
      mySqlDump.IncludeDrop = true;
      mySqlDump.GenerateHeader = true;
      mySqlDump.Tables = "Dept;Emp";
      mySqlDump.Backup();
      StreamWriter stream = new StreamWriter("d:\\tmp\\mysqldump.dmp");
      stream.WriteLine(mySqlDump.DumpText);
      stream.Close();
      Console.WriteLine("Dumped.");
      myConnection.Close();
    }
    
    public void UnDumpIt(MySqlConnection myConnection)
    {
      myConnection.Open();
      MySqlDump mySqlDump = new MySqlDump();
      mySqlDump.Connection = myConnection;
      myConnection.Database = "Test";
      StreamReader stream = new StreamReader("d:\\tmp\\mysqldump.dmp");
      mySqlDump.DumpText = stream.ReadToEnd();
      stream.Close();
      mySqlDump.Restore();
      Console.WriteLine("Restored.");
      myConnection.Close();
    }
    Public Sub DumpIt(ByVal myConnection As MySqlConnection)
      myConnection.Open()
      Dim mySqlDump As MySqlDump = New MySqlDump
      mySqlDump.Connection = myConnection
      myConnection.Database = "Test"
      mySqlDump.IncludeDrop = True
      mySqlDump.GenerateHeader = True
      mySqlDump.Tables = "Emp;Dept"
      mySqlDump.Backup()
      Dim stream As StreamWriter = New StreamWriter("d:\tmp\mysqldump.dmp")
      stream.WriteLine(mySqlDump.DumpText)
      stream.Close()
      Console.WriteLine("Dumped.")
      myConnection.Close()
    End Sub
    
    Public Sub UnDumpIt(ByVal myConnection As MySqlConnection)
      myConnection.Open()
      Dim mySqlDump As MySqlDump = New MySqlDump
      mySqlDump.Connection = myConnection
      myConnection.Database = "Test"
      Dim stream As StreamReader = New StreamReader("d:\tmp\mysqldump.dmp")
      mySqlDump.DumpText = stream.ReadToEnd()
      stream.Close()
      mySqlDump.Restore()
      Console.WriteLine("Restored.")
      myConnection.Close()
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             Devart.Common.DbDump
                Devart.Data.MySql.MySqlDump

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also