SQL Server Attach Database Error

In the scenario where you only have the MDF file of the SQL Server database, you can convert this file into a real database that can be accessed through SQL Server Management Studio by using the “Attach” method. This is a method of moving very large databases directly between servers, sometimes without backing them up. Of course, in order to do this, you must first stop the SQL Server service on the source server.

When you want to restore the MDF file you copied from a server with the “Attach” method on the new SQL Server, you must first right-click on the new server and select the “Attach” option.

You can select your MDF file on the screen.

After the selection process, you will most likely see the screen with the following error message.

“CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file …” (Microsoft SQL Server, Error: 5123)

The main reason for this error is that while you were moving files between servers, information regarding the ownership of the file was lost. In this example, when you right-click on the MDF file and access its properties, you will get an error message like the one below.

“You must have Read permissions to view the properties of this object”

To solve this problem, let’s click on the “Advanced” button.

When you click the “Advanced” button, you will see the following message in the owner of the file.

“Unable to display current owner”

And again the same “You must have Read permissions to view the properties of this object” error. I guess we really don’t have the authority 😊 To solve this problem, click the “Change” link and take ownership by selecting the user to perform the action on the screen that opens

Normally these steps should resolve your issue. However, sometimes this is not enough and you will get the same error again. In this case, you should open SQL Server Management Studio in “Run as Administrator” mode and try the same operation again.

When we repeat the same steps with SQL Server opened in “Run as Administrator” mode, we will see that we can select the file without any errors.

And, of course, that the operation was successful.

Add a Comment

Your email address will not be published. Required fields are marked *