#region 备份
private void BeiFen()
{
try
{
string strg = Application.StartupPath.ToString();
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg += @"\Data"; string backSQL = @"BACKUP DATABASE jxc TO Disk='" + strg + "\\" + "" + ".bak" + "'";
DbHelperSQL.ExecuteSql(backSQL);
if (MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
#endregion
备份时报错语法问题?错误是《‘’》
private void BeiFen()
{
try
{
string strg = Application.StartupPath.ToString();
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg += @"\Data"; string backSQL = @"BACKUP DATABASE jxc TO Disk='" + strg + "\\" + "" + ".bak" + "'";
DbHelperSQL.ExecuteSql(backSQL);
if (MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
#endregion
备份时报错语法问题?错误是《‘’》
BACKUP DATABASE jxc TO Disk='E:\0528\20130605\杨林耗材进销存系统\jxc\Data\aa.bak'
BACKUP DATABASE jxc TO Disk='E:\0528\20130605\杨林耗材进销存系统\jxc\Data\aa.bak'
这个语法没错啊,你在SSMS中可以正常执行吗?
请问LZ程序所连的数据库是SQL Server吗?
把此句SQL单独放在SSMS里执行是否正常?
在数据执行没有问题?在C#应用程序执行就报错??错误如图
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.SqlClient.SqlException e)
{
connection.Close();
throw e;
}
}
}
}
private void BeiFen()
{
if (saveFileDialog1.ShowDialog() != DialogResult.OK) return; string backfilename = saveFileDialog1.FileName; string backSQL = @"backup database 数据库名 to disk='" + backfilename + "'with init"; try
{
DbHelperSQL.ExecuteSql(backSQL);
MessageBox.Show("数据库备份成功", "数据库备份", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
#endregion我换了一种方法就行了谢谢大家的回答