在localdb 2012中数据库路径很长时为备份或还原操作指定的数据库名称无效

时间:2015-02-17 19:31:52

标签: c# entity-framework localdb

我使用带有EF的sql server localdb v11.0。 我使用以下代码进行备份:

public void BackupDatabase(string filePath, string DbPath)
{
    using (CameraManDBEntities dbEntities = new CameraManDBEntities())
    {
        string backupQuery = @"BACKUP DATABASE @DbPath TO DISK = N'{0}'";
        backupQuery = string.Format(backupQuery, filePath);

        dbEntities.Database.SqlQuery<object>(backupQuery, new SqlParameter("DbPath", DbPath)).ToList().FirstOrDefault();
    }
}

当我调用以下方法时:

BackupDatabase(BackUpFileName, @"C:\Users\Mahmood\AppData\Local\Apps\2.0\ZV0DG5JM.3OH\XQ31WEZB.OKA\camman.exe_af50f6b9afda55f2_0001.0005_none_2c544a12b9bb2c09" + "\\CameraManDB.mdf");

它引发了这个异常:

Invalid database name 'C:\Users\Mahmood\AppData\Local\Apps\2.0\ZV0DG5JM.3OH\XQ31WEZB.OKA\camman.exe_af50f6b9afda55f2_0001.0005_none_2c544a12b9bb2c09\CameraManDB.mdf' specified for backup or restore operation.\r\nBACKUP DATABASE is terminating abnormally.

当我使用短路径作为数据库名称参数时,例如&#34; E:\ PROGRAMMING \ CAMMAN \ CAMMAN \ BIN \ RELEASE \ CAMERAMANDB.MDF&#34;,它工作正常。

0 个答案:

没有答案