You get a bonus - 1 coin for daily activity. Now you have 1 coin

MS SQL: migrated databases attach in read-only mode only

Practice



So, to set the stage: we have a Microsoft SQL Server installed on Windows Server 2008 or higher. And it doesn't matter whether we're running SQL Standard, SQL Enterprise, or SQL Express — the situation is the same.

As long as the databases sit in their default location, i.e. under Program Files, everything is fine. But as soon as we move them to another folder (let alone another drive) - problems immediately appear.

The problem is that MS SQL Server either refuses to attach the moved databases at all, or attaches them, but only in "read-only" mode.


Solution.

The problem lies in the permissions on the folder you moved the databases to. The thing is, by default MS SQL Server doesn't have write access there, and accordingly it doesn't work correctly.

To find out which permissions this folder needs, go to the location where these databases live by default on this particular server (for example,
C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL

), right-click on the folder with the databases (usually "DATA"), select "Properties" from the context menu, then go to the "Security" tab and check the current permissions.

You'll see an entry like "SQLServerMSSQLUser$HOSTNAME$SQLExpress" or something similar (instead of HOSTNAME - your server's name, instead of SQLExpress - the instance name or nothing).


Now head over to where you copied the databases, and add this group with full permissions in the security settings (and yes, by the way, it's a group, not a user).

Now read carefully! Simply typing part of the group name and clicking "Check Names" won't add it! Windows will behave as if no such group exists - not in the system, not in the domain, nowhere at all. Why it's done this way is a mystery (since it doesn't add any security - out of desperation, admins end up adding the "Everyone" group and granting maximum permissions on the folder).
You need to type the group name IN FULL. Every single character! Exactly, character for character, as written on the "Security" tab of the "DATA" folder, where the databases live by default on THIS server. If you miss even one character, the group won't be recognized. And it doesn't matter which object types you select for the search - the OS will keep saying no such object exists until you type it character for character.


So, we've added the group with maximum permissions to the folder where the required databases now sit — and we try attaching them in MS SQL Server again. It should work now.

Applies to: Microsoft SQL Server 2008 (possibly 2005) + Windows Server 2008 and above

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)