c# - 使用 SMO 更改逻辑数据库名称

标签 c# sql-server smo

如何在使用 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/

相关文章:

c# - 使用密码分离数据库

c# - Linq 分组

c# - 将自定义 header 添加到 .Net 中的所有 Swagger 响应

c# - 是否有可能编写完全可维护的代码?

sql - Soundex 函数在 SQL Server 中如何工作?

c# - 使用 SQL 管理对象 (SMO) 连接到 SQL,我如何才能查明 View 是否有任何行?

c# - 从代码隐藏中调用 JavaScript 函数

sql-server - MS SQL Server 2012 将日期时间导出为无法导入的脚本

sql - 如何解锁 SQL Server 2005 Management Studio 中的用户帐户?