1
I am building a button to make a backup of mine db
via application C#
,
everything is going well, but at the time of applying the Executenonquery is accusing error of syntax
.
Follows:
Designate Path:
private void Browser_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dlg.SelectedPath;
FazerBackup.Enabled = true;
}
}
Back up:
private void FazerBackup_Click(object sender, EventArgs e)
{
MySqlConnection conexao = ClassConexao.ObterConexao();
try
{
string data = conexao.Database.ToString();
string cmd = "backup database [" + data + "] to disk='" + textBox1.Text + "\\" + "database" + "-" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".bak'";
using (MySqlCommand command = new MySqlCommand(cmd, conexao))
{
if (conexao.State != ConnectionState.Open)
{
conexao.Open();
}
command.ExecuteNonQuery();
conexao.Close();
MessageBox.Show("Sucesso");
}
}
catch (Exception error)
{
MessageBox.Show(String.Format("Check the fields {0}", error.Message));
return;
}
}
Connection is already open and the path(Path) is already in the box.
Error:
Ps: Same direct on Mysql - SQL Editor this syntax is not working; strange, because every tutorial I see, is exactly the same.
You can post the generated command?
– Jéf Bueno
What do you mean @LINQ ? this is all my command, all I do before is open the connection and designate the path within the textbox.
– Maurício Sanches
The SQL generated, young.
– Jéf Bueno
The value of the variable
cmd
.– Jéf Bueno
cmd = "backup database [" + data + "] to disk='" + textBox1.Text + " " + "database" + "-" + Datetime.Now.Tostring("yyyy-MM-dd-HH-mm-ss") + ". Bak'";
– Maurício Sanches
The value, young man, the value, at runtime. The generated SQL command.
– Jéf Bueno
"backup database [eaglemotors] to disk='C: Backup database-2017-08-23-13-40-37.Bak'"
– Maurício Sanches
This is to be Mysql or SQL Server?
– Jéf Bueno
Mysql @LINQ.....
– Maurício Sanches
This is a statement from SQL Server, not Mysql.
– Jéf Bueno
Putz ! @LINQ que mancada heim. , thanks for identifying the error so, I’ll get the Mysql.
– Maurício Sanches