如何在使用 SMO 恢复数据库时更改逻辑数据库名称?
/维克托
最佳答案
//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");
关于c# - 使用 SMO 更改逻辑数据库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301226/