Error 5123 Unable To Attach Database
Contents |
More > Database Administration Problem When you attach a database in SQL Server 2008R2 which was detached by a user with a different login you may get this error: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical error 5120 in sql server 2008 file... (Microsoft SQL Server, Error 5123) This is a screenshot of the error: In this tip
Microsoft Sql Server Error 5120
we will cover how this can be resolved. Solution You get this error because two different logins did the detach and attach operations. So the files,
Microsoft Sql Server Error 5133
when detached, were owned by the first login, but the attach failed because the login that was used was not the owner of the mdf and ldf files. When we detach database files, the owner becomes the person who did the
Microsoft Sql Server Error 5120 Access Denied
detach command, so to resolve the issue we need to change or add the other login as the owner of the mdf and ldf files. Find the below steps to resolve this issue. Steps Lets consider that someone detached a database and you have to attach it to bring the database online. For this example, we will use two logins to perform this activity. I will detach the database using the first login and then try to attach it with the second login. Not sql server error 5123 create database that both accounts are part of the local administrator group on the server. Step 1Here I detach the database named "stats1" with my login account. Step 2Now I have logged in with the second account and will try to attach the database, but during this process I am getting the below error. Step 3Right click on the "stats1.mdf" file and select properties to check the permissions of the mdf file. Here we can see that only one account has permission to the "stats1.mdf" file because that was the account that was used to detach the database. Step 4To resolve this issue, click on the Add... button to add the other login or any other login needed and give the login Full Control. You should do this for the "ldf" file as well. Once you have completed this task click the OK button. (Note for other OS versions you may have an Edit option , click this first and then you will see the Add... option.) Step 5Now try the attach again and it should work. The permissions prevented the files from being modified should they reside in a directory that has open permissions. For example, if the permissions are not set and the operating system permissions on the database directory are set to Full Control for everyone any account that has access to that directory can delete or modify the database files even though they may not have SQL Server permissions to modify the database itself. Next Steps If
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or sql error 5123 access denied posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss sql error 5123 create database Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes error 5123 in sql server 2014 a minute: Sign up Cannot attach database SQL Server 2012 error 5 up vote 0 down vote favorite When I type this: CREATE DATABASE AdventureWorks2012 ON (FILENAME = 'C:\Users\sohm\Desktop\Pohm\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG ; I get this: File activation failure. The physical https://www.mssqltips.com/sqlservertip/2528/database-attach-failure-in-sql-server-2008-r2/ file name "C:\Users\sohm\Desktop\AdventureWorks2012_Data_log.ldf" may be incorrect. Msg 5123, Level 16, State 1, Line 1 CREATE FILE encountered operating system error 5 (Access is denied.) while attempting to open or create the physical file 'C:\adventuredb\AdventureWorks2012_Data_log.ldf'. Msg 1813, Level 16, State 2, Line 1 Could not open new database 'AdventureWorks2012'. CREATE DATABASE is aborted. I know it has to do with permissions. I have the administrator account. I have read a million posts but nothing has worked so far. Also when I try to http://stackoverflow.com/questions/14989930/cannot-attach-database-sql-server-2012-error-5 change the folder containing the mdf file, to full control but it keeps reverting back to read-only. sql sql-server-2012 share|improve this question edited Feb 20 '13 at 21:18 marc_s 452k938641029 asked Feb 20 '13 at 21:08 eaglecoug 23125 Make sure it is not attached already, SQL server takes full control of MDF files. –Ulises Feb 20 '13 at 21:09 I did, the db is not attached –eaglecoug Feb 20 '13 at 21:13 2 Make sure that the account running the sql server service has full control over that folder as it will need to read the MDF and create a new LDF file in there. Ignore the read only attribute on the folder, it's generally ignored in windows and is used mostly for folder customisation. –steoleary Feb 20 '13 at 21:15 I am logged in Windows with the default admin account. How do I set full control over the folder? Because when I right click the folder and go to security, I have full access. –eaglecoug Feb 20 '13 at 21:18 4 You could be logged on as God, SQL Server is not you. –Aaron Bertrand Feb 20 '13 at 21:22 add a comment| 6 Answers 6 active oldest votes up vote 9 down vote You should run SSMS as an administrator. Also it is possible that you might be running query as an 'sa' user(sql server authentication). Try running the query with window
/ Trainingen Katwijkse duinen vorige week Contact / Vragen / Informatie Home / StartpaginaWie zijn wij ?Knowledge / FAQ'sLekkerThanks to....Zakelijke dienstenOpleiding / LearningOpinieDisclaimer / Privacy Contact SQL - http://oostdam.info/index.php/sectie-blog/137-sql-error-5123 Error 5123 problems attaching DB Microsoft SQL Server is a great product to work with. Especially from the release of version 2005 and now 2008. For me, it is the standard for all kinds of databases. The Object explorer, Tuning Advisor, the Query Analyser and T-SQL statements work great, and are a joy to work sql server with. When it goes wrong somewhere, it is mostly a syntax error, program(bug) error or a user error that causes the problem. Stable as it is, I can recomment the use of it to anyone. In this articles I like to share with you, some errors and "best practices" that came up during my work several sql server error times. So, initially set up was for my own references, now I share it with you. Enjoy these articles!! Due to the fact that a big percentage of visitors of this page are international based, this article is in the english language.Error 5123 when attaching a database:This is a common error which i've seen on many occasions. Sometimes you have to detach a database. You cannot allwys use backup files or other solution. This error can occur when you try to attach the database again, mostly on different locations. Mostly it is something like: SQL Server -Error 5123 : Cannot attach DB. Please check the following things which each can be the source of your problems:Check the exact database names and file paths.Disable your Anti Virus Software, this could "lock" your database as well.Check if backup software is "locking" de Database.Give NTFS security permissions for the MDF and LDF files to "Everyone".( and on that directory or (mapped) disk letterMove the files to a sub directory, root directories c