SQL Server Error 5123


Are you trying to attach a database to SQL Server Management Studio and getting Error 5123? Are you trying to attach a database and getting operating system error 5 (Access is denied)? They are the same errors.

Error 5123/Access Is Denied

One solution that worked for me was to run SSSMS as the Administrator. Click on Start, find your program, and right-click it. Click on Run As Administrator.

If you want to always run as Administrator you can follow these steps. Open the Start menu and find the program you want to always run in administrator mode and right-click on the shortcut. In the pop-up menu, click Open file location. Only desktop programs (not native Windows 10 apps) will have this option. A File Explorer window will open to the location of the program you want to access. Right-click on the program file (exe) and click Properties from the pop-up menu. In the Properties window, click the Shortcut tab and then click Advanced… In the Advanced Properties window, check the box next to Run as administrator and click OK. The program will now open in administrator mode when you click the shortcut from the Start menu. You’ll need to repeat these steps for each program you want to have this feature. You can now pin it to the Start menu and/or pin it to the taskbar (if you use it often) and those shortcuts will also always run as the Administrator.

You might encounter this error 5123 if you uninstall and re-install SQL Server and SSMS and you find that you need to Attach your databases because they no longer appear under Databases in SSMS. This happened to me.

The problem might be in the security permissions of the database (mdb) and log files (log). Use Windows Explorer to get the properties of the database file. After you set the permissions here you will need to also set the permissions on the log file. If you are in SQL Server Management Studio and you right-click Databases and click Attach.. and click the Add button and navigate out to your database file location and select the mdb file and attempt to attach it. You might get this error. The solution might be to change the security. Here is how. Using Windows Explorer, select the mdb file, right-click and get the properties. Select the Security tab and click the Advanced button. Click the Continue button. Click the Add button. Click the Select a principal link. Click Advanced and Find Now. A list of users and groups should appear. You can choose your own Windows login name. Click Ok and also click the check box for Full Control. Click Ok three more times. Do this for the mdb and log files. Now you should be able to attach the database in SSMS.