Use smo to rename datafiles

我的梦境 提交于 2019-12-05 03:51:20

问题


How can I use SMO to rename the physical .mdf .ndf .ldf files. This article was helpful but I need to use C# SMO Objects.

Using the SMO Server Object I can retrieve the database, then Get Access to the DataFile objects. Per this link. These have a Rename, however after rename, nothing changes.


回答1:


Well, I haven't tried this, but as per your first link, you can detach the database, rename the file on disk and then re-attach the database. So, give that a shot.

The Server object in SMO has a Detach(..) and Attach(..) methods that you can use. Then, just use File.Move(..) to rename the file.



来源:https://stackoverflow.com/questions/425296/use-smo-to-rename-datafiles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!