Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 SMO 重命名物理 .mdf .ndf .ldf 文件。 这篇文章很有帮助,但我需要使用 C# SMO 对象。
使用 SMO 服务器对象,我可以检索数据库,然后访问 DataFile 对象。根据这个链接。这些有重命名,但是重命名后,没有任何变化。
好吧,我还没有尝试过,但是根据您的第一个链接,您可以分离数据库,重命名磁盘上的文件,然后重新附加数据库。所以,试一试。
SMO 中的 Server 对象具有您可以使用的 Detach(..) 和 Attach(..) 方法。然后,只需使用 File.Move(..) 重命名文件。