Serves to store a database or its parts as a script and to restore database from the generated script.
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
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