Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i want to make backup from my sql, and using save dialog to define save path
this is my code
<pre><pre lang="c#">
string strFileName = string.Empty;
saveFileDialog1.FileName = "backup file ";
saveFileDialog1.Filter = @"SQL Backup Files (*.BAK)|*.BAK |All Files(*.*)|*.*)";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.Title = "Backup SQl files";
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
strFileName = saveFileDialog1.FileName.ToString();
}
try
{
bool bBackUpStatus = true;
Cursor.Current = Cursors.WaitCursor;
if (Directory.Exists(strFileName))
{
if (File.Exists(strFileName))
{
if (MessageBox.Show(@"do you want replace?",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(strFileName );
}
else
bBackUpStatus = false;
}
}
else
Directory.CreateDirectory(strFileName );
if (bBackUpStatus)
{
// Connect to DB
SqlConnection connect;
string con = "data source =" + Dns.GetHostName() + @"\SQLEXPRESS;initial catalog=library;integrated security=true";
connect = new SqlConnection(con);
connect.Open();
//----------------------------------------------------------------------------------------------------
//Execute SQL---------------

SqlCommand command;
command = new SqlCommand("backup database [library] to disk=" + strFileName.ToString() + "", connect);
command.ExecuteNonQuery();
//-------------------------------------------------------------------------------------------------------------------------------
connect.Close();
MessageBox.Show("Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show("error", MessageBoxButtons.OK, MessageBoxIcon.Information);

}



</pre></pre>
Posted
Comments
[no name] 27-Feb-12 7:31am    
So, what is the problem?

1 solution

You are asking Question backup for mysql but your code written for sql server ?

You can take backup by following two methods :
1. use mysql command : mysqldump -u username -pPASSWORD filenamewithpath
2. connect with database and by select query take all data to dataset and export as .csv format
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900