Please help. I recently downloaded a trial 30 days dotConnect for MySQL. I plan to buy it after trial expired. I am writing an web application (C#) to allow user backup and restore MySQL database. I don't know how to export each table into separate file while dumping it.
Please help. Thanks
how export each table into separate file (DUMP)
-
- Posts: 4
- Joined: Fri 16 Dec 2011 19:04
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
I have created a little example that allows backing up each table to a different file. The sample backs up all the tables in the 'test' database.
In my case, I have received 71 files in folder 'D:\tempdir'
Code: Select all
MySqlConnection conn = new MySqlConnection("Your connection string; database=test;");
conn.Open();
MySqlCommand comm = new MySqlCommand("show tables", conn);
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(comm);
da.Fill(dt);
MySqlDump dump = new MySqlDump();
dump.Connection = conn;
dump.Database = "test";
string[] fileNames = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
fileNames[i] = "D:\tempdir\file" + i.ToString()+".txt";
dump.Tables = dt.Rows[i][0].ToString();
dump.Backup(fileNames[i]);
}
conn.Close();