我的项目中有一个部分,网站管理员可以在其中创建和下载临时数据库备份。这是代码
[HttpPost]
public ActionResult Backup(DatabaseBackupViewModel model)
{
var conStr = System.Web.Configuration.WebConfigurationManager.AppSettings["ConStr"];
var backupFolder = System.Web.HttpContext.Current.Server.MapPath("\\content\\db-backup\\");
var backupFilename = String.Format("bkp-{0}-{1}.bak", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture));
using (var connection = new SqlConnection(conStr))
{
var query = String.Format("BACKUP DATABASE dbname TO DISK='{0}'", backupFolder + backupFilename);
using (var command = new SqlCommand(query, connection))
{
connection.Open();
command.ExecuteNonQuery();
//Save to database.
var bkp = new DatabaseBackupLog
{
BackupId = Guid.NewGuid(),
BackupTitle = model.Title,
BackupFilename = backupFilename,
BackupDate = DateTime.Now
};
_service = new DatabaseService();
_service.Create(bkp);
}
}
return View(model);
}
上面的代码在我的本地很有用,但是当我尝试在远程备份数据库时,我收到以下错误:
Cannot open backup device...
Operating system error 3(The system cannot find the path specified.).
BACKUP DATABASE is terminating abnormally.
我仔细检查了 - 文件夹位于正确的位置。文件夹的名称没有拼写错误或任何东西。我甚至从我的主机控制面板授予该文件夹的所有用户帐户的完全权限。
什么都行不通!不知道出了什么问题。 请帮忙
提前感谢