使用SMO重命名数据文件重命名、文件、数据、SMO

2023-09-03 05:27:34 作者:世界与我无关 #

如何使用SMO重命名.NDF .ldf文件的物理.MDF。 这文章是有益的,但​​我需要使用C#SMO对象。

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.

使用SMO服务器对象,我可以检索数据库,然后可以访问数据文件的对象。每本链接。这些有重,但重命名后,没有什么变化。

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.

推荐答案

嗯,我没有试过,但根据您的第一个环节,你可以分离数据库,重命名磁盘上的文件,然后重新连接数据库。所以,给这一个镜头。

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.

在SMO的Server对象有一个分离(..)和附加(..)方法,您可以使用。然后,只需使用File.Move(..)重命名的文件。

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