Search code examples
.netsmo

When attaching database with SMO, the database is readonly


I'm just trying to detach a database and reattach it using a different pair of mdf/ldf files using code like this:

Server server = GetMyServer();
server.AttachDatabase(myDatabaseName, new StringCollection { mdfFile, ldfFile }, AttachOptions.None);

When I check out the results of the above code in management studio, though, the database I've attached is read-only. Any ideas as to why and how to fix this? Thanks.


Solution

  • Never mind, silly oversight: I realized it was a matter of folder permissions. The ones for the directory containing the database files to be attached weren't set correctly.