Asp.net backup database problem


Why always tip: syntax error near the '-'. Alert ('backup data failed!')

string cmdtxt2 = @"backup database l-xian to disk='" + path + ".bak'";
SqlConnection Con = new SqlConnection(@"Server='WIN-A3CE67RFII8\SQLEXPRESS';database=longteng;Uid=sa;Pwd=111111");
Con.Open();
try
{
SqlCommand Com = new SqlCommand(cmdtxt2, Con);
Com.ExecuteNonQuery();
Response.Write("<scriptlanguage=javascript>alert('Backup data!');</script>");
}
catch (Exception ms)
{
Response.Write(ms.Message);
Response.Write("<scriptlanguage=javascript>alert('Backup data failed!')</script>");
}
finally
{
Con.Close();
}

Started by Eugene at November 18, 2016 - 4:07 PM

[l-xian]

*****************************************************************************
Signature

Posted by Blithe at November 19, 2016 - 4:51 PM

L-xian to add brackets
[l-xian]
Otherwise the SQL will be as the L variable Xian minus the variables.

Posted by Charles at December 01, 2016 - 5:30 PM

+1

Posted by Nikita at December 05, 2016 - 5:45 PM