我正在使用此代码恢复 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);
我正在使用代号为“Denali”Express Core (CTP 3) 的 SQL Server。
此代码在开发人员 PC 上运行良好,但在客户端的 PC 上,它会引发此异常:
服务器 xxxx/SQLExpress 恢复失败
我不明白我错在哪里。
内部异常是:
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)