Forum Navigation
Please to create posts and topics.

SQL Server - SQL Attach DB: Could not open new database.

I am getting an error while trying attaching a database (SQL Server) to a new SQL Server database instance.

The error I'm getting is the following:

Msg 3415, Level 16, State 5, Line 3
Database 'DB_to_Import' cannot be upgraded because it is read-only,
has read-only files or the user does not have permissions
to modify some of the files. Make the database or files writeable, and rerun recovery.
Msg 1813, Level 16, State 2, Line 3
Could not open new database 'DB_to_Import'. CREATE DATABASE is aborted.

How to fix it?

There are few workarounds can be follow toward the issue resolution. You must ensure the following criteria are met.

  • Launch the Microsoft SQL Management Studio as Run as administrator (especially in case of different location of database files).
  • Locate the database files (mdf, ndf, ldf) and ensure that your logged user has access to theses files / folders.
  • Do not use sa (system administrator) user.
  • Login with Windows Authentication. Do not use SQL Server authentication.

Specifically, if you are trying attaching database (mdf, ndf, ldf files) from a different location (usually not in C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA or in C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA) this could lead to the error; two possible solution for this scenario (in case of different location of the database files) are:

  1. Move .mdf and .ldf to SQLServer install directory \Data\ folder (eg. C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA).
  2. Add rights to the SQL Server user to the directory you need access to. Right-click the folder. Select Properties. Select "Security" tab. Click "Edit". Select "NT Service\MSSQLSERVER". Finally click the "Allow" tickbox next to "Full control" under "Permissions for Users".