尝试备份和还原数据库时出现此错误。
后端:
SQL server 2008
前端: C#
使用数据库备份和还原期间路径中的非法字符C#
private void backToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
string FileToMove = null;
string MoveLocation = null;
string FileToDel = null;
FileToMove = "|DataDirectory|\\CMS_DB.mdf";
MoveLocation = "|DataDirectory|\\backup\\CMS_DB.mdf";
FileToDel = "|DataDirectory|\\backup\\CMS_DB.mdf";
if (MessageBox.Show("Are you sure you want to backup current database?", "CONFIRMATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
{
System.IO.File.Delete(FileToDel);
System.IO.File.Copy(FileToMove, MoveLocation);
MessageBox.Show("Database successfully backup!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
string FileToMove = null;
string MoveLocation = null;
string FileToDel = null;
FileToMove = "|DataDirectory|\\CMS_DB.mdf";
MoveLocation = "|DataDirectory|\\backup\\CMS_DB.mdf";
FileToDel = "|DataDirectory|\\backup\\CMS_DB.mdf";
if (MessageBox.Show("Are you sure want to permanently replace current database with the backup database?", "CONFIRMATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
{
System.IO.File.Delete(FileToDel);
System.IO.File.Copy(FileToMove, MoveLocation);
MessageBox.Show("Database successfully restored!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
请帮助解决这个问题。