Rah*_*hul 10
//restore is the Restore object in SMO
restore.RelocateFiles.Add(new RelocateFile(SourceDataFile.Name, Path.Combine(destinationDirectory, destination.Database + ".mdf")));
restore.RelocateFiles.Add(new RelocateFile(SourceLogFile.Name, Path.Combine(destinationDirectory, destination.Database + "_log.ldf")));
restore.SqlRestore(destinationServer);
var destinationDatabase = destinationServer.Databases[destinationDatabaseName];
//renaming the logical files does the trick
destinationDatabase.FileGroups[0].Files[0].Rename(destinationDatabaseName);
destinationDatabase.LogFiles[0].Rename(destinationDatabaseName + "_log");
Run Code Online (Sandbox Code Playgroud)
您不能使用SQL RESTORE DATABASE重命名逻辑数据库文件:未提供。使用WITH MOVE只能更改物理文件
通常,可以使用SQL中的ALTER DATABASE重命名逻辑文件。
这似乎已由RelocateFile SMO类确认。
| 归档时间: |
|
| 查看次数: |
5220 次 |
| 最近记录: |