views:

532

answers:

1

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  A: 

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.

BFree
You may encounter file permission problems if you try to use File.Move because you are circumventing SQL Server which by default is the only process that has access to its data directory
Schneider