我正在使用此代碼恢復SQL Server數據庫服務器xxxx/SQLExpress的還原失敗
Server databaseServer = new Server(new ServerConnection(CvVariables.SQL_SERVER_NAME));
string databasePath = System.IO.Path.Combine(Environment.CurrentDirectory,);
string databasePath = @"D:\cvdb.bak";
Restore databaseRestore = new Restore();
databaseRestore.Action = RestoreActionType.Database;
databaseRestore.Database = CvVariables.Catalog;
databaseRestore.Devices.Add(new BackupDeviceItem(databasePath, DeviceType.File));
databaseRestore.ReplaceDatabase = true;
databaseRestore.SqlRestore(databaseServer);
我使用的是代號爲'Denali'Express Core(CTP 3)的SQL Server。
此代碼在開發人員PC上工作正常,但在客戶端的PC上,它會拋出此異常:
服務器xxxx/SQLExpress
恢復失敗我不明白我在哪裏錯誤。
InnerException是:
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Cafeteria_Vernier_db.mdf" failed with the operating system error 3(The system cannot find the path specified.).
File 'Cafeteria_Vernier_db' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Cafeteria_Vernier_db.mdf'. Use WITH MOVE to identify a valid location for the file.
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Cafeteria_Vernier_db_log.ldf" failed with the operating system error 3(The system cannot find the path specified.).
File 'Cafeteria_Vernier_db_log' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Cafeteria_Vernier_db_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
RESTORE DATABASE is terminating abnormally.
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
服務器是否是相同的版本。 SQL Server不喜歡從較新的SQL Server版本恢復備份。信息消息中通常有更多的信息。您可以從Management Studio恢復服務器上的備份嗎? –
是的,兩者都是相同的版本,是的我從Management Studio存儲在服務器上的備份。 – Vero009
您是否在異常情況,狀態代碼,內部異常中獲得更多信息? –