Я использую этот код для восстановления базы данных SQL Server
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);
Я использую SQL Server с кодовым названием Denali Express Core (CTP 3).
Этот код отлично работает на компьютере разработчика, но на компьютере клиента он выдает следующее исключение:
Ошибка восстановления для сервера xxxx / SQLExpress
Я не понимаю, где я неправ.
InnerException Is:
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)