Table of Content
    SQL Database Repair

    How To Fix The SQL Server Error 3415


    Table of Content

      Summary: The error 3415 occurs when you try to attach a database to SQL Server. In this article, we will talk about this error, the situations when this error occurs, and the solutions to fix this error. We’ll also mention a SQL repair software that can help resolve the issue if it has occurred due to corrupt or damaged SQL database.

      While trying to attach a database in SQL Server, you may receive the error 3415. When the error 3415 in SQL Server occurs, you may receive an error message similar to the below one:

      Error 3415, Severity 16

      Database Adventureworks is read-only or has read-only files and must be made writable before it can be upgraded.

      As you can see, this error has a severity of 16, which means that the user can fix the problem.

      When this problem occurs?

      To understand the issue, we can try to reproduce the problem. For this, we can detach a database from one server by opening the SSMS and then going to Tasks > Detach.

      in object explorer, detach your db from tasks
      • Then, we can try to attach the database to a folder that doesn’t have enough permissions.
      attach option by right-clicking on database folder

      Alternatively, we can use the T-SQL commands to detach the database (see the below example).

      USE [master]
      GO
      EXEC master.dbo.sp_detach_db @dbname = N’Database_name’
      GO

      Now, we will try to attach the database. For this, we can use the sp_attach_db stored procedure.

      USE [master]
      GO
      EXEC sp_attach_db @dbname = N’db1′,
      @FILENAME1 = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\DATA\DB1.mdf’,
      @FILENAME2 = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\DATA\DB1_log.ldf’;

      Alternatively, we can attach the database using the CREATE DATABASE command (see the below example).

      USE [master]
      GO
      CREATE DATABASE [db1] ON
      ( FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\DATA\DB1.mdf’ ),
      ( FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER03\MSSQL\DATA\DB1_log.ldf’ )
      FOR ATTACH
      GO

      How to Resolve the Error 3415 in SQL Server?

      Here are some solutions you can try to resolve the error.

      Check Privileges in the SQL Server Service Account

      SQL Server runs under the SQL Server Service account. The SQL Server Service is a program that executes SQL Server Database Engine. This service runs under a Windows user account. Sometimes, this account does not have enough permissions to manipulate the SQL Server data and log files.

      The data files contain the SQL Server database information, whereas the log files contain the transaction information.

      • To check the folder where the data files and log files are installed, right-click the database and select properties.
      • Select the Files page and look for the Path. It will show the path of the log and data files.
      Select the files page to view path of log and data files
      • To check the account used by the SQL Server, go to the Windows Start menu and select Microsoft SQL Server > SQL Server Configuration Manager.
      • In the SQL Server Configuration Manager, go to SQL Server Services and double-click the SQL Server service.
      in sql server config manager, go to sql server services and double-click on SQL Server
      • We can see the Account name. We can change it to another account by using the browse button.
      • If we change the account name, we need to restart the service.
      you can change account name and click on restart
      • After knowing the account, in the properties, go to the folder with the data files. Right-click the folder and select Properties.
      • In Properties, go to the Security tab and select Edit.
      right click on folder with data files and click on properties. 
Go to security tab and click on edit.
      • In the Permission for Data window, press the Add button to add the service name account, if it is not included. Once added, assign the permissions to the folder.
      in properties of the folder of data files, go to the security tab and allow all permissions for user.

      Run SSMS as Administrator

      Sometimes, the problem occurs if we’re not running the SSMS (SQL Server Management Studio) as an administrator. To solve this, right-click the SSMS icon and select the Run as administrator option.

      run as administrator option

      What to do if the data file is damaged?

      When the data file is damaged, you may fail to attach the database. In such a case, you can use a third-party software, such as Stellar Repair for MS SQL to fix the problem. This software can repair the database file in just a few clicks. Then, you would be able to attach the database without error.

      Conclusion

      In this article, we have explained how to fix the SQL Server error 3415. This error usually occurs when there are not enough permissions in the SQL Server service to access the data file and transaction log folders. The error may also occur if the user is not running the SSMS as an administrator. To fix the problem, you can grant permissions to the folder and run SSMS as administrator. If the database file is corrupt, you can repair the file by using a professional SQL repair tool, such as Stellar Repair for MS SQL.

      Was this article helpful?

      No NO

      About The Author

      Bharat Bhushan linkdin

      Bharat Bhushan is an experienced technical Marketer working at Stellar Data Recovery - expertise in data care. He is skilled in Microsoft Exchange Database, MSSQL Database troubleshooting & data warehousing. He is a Management Post Graduate having a strong grip in Technology & certified in SAP-SD, Oracle 10g & Informatica Powercenter 9.1.

      Leave a comment

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

      Image Captcha
      Refresh Image Captcha

      Enter Captcha Here :

      Related Posts

      WHY STELLAR® IS GLOBAL LEADER

      Why Choose Stellar?

      • 0M+

        Customers

      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+

        Countries

      • 0+

        PARTNERS

      • 0+

        Awards Received