0

“ERROR 5123” in MS SQL Server while attaching; i've tried many ways but i haven't get a solution yet

Hello, How are you?

I have a database with 3 tables created by Microsoft SQL Server and I want to "ATTACH" this database. When I use "attach" in

SQL Server I receive the following error:

=============================================

TITLE: Microsoft SQL Server Management Studio

Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476


ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)


CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file

'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\test.mdf'. (Microsoft SQL Server, Error: 5123)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL

%20Server&ProdVer=12.00.4100&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476


BUTTONS:

OK

================================================

by the way, i tried many ways to solve this problem but my problem haven't solved yet, such as: Changing my SQL Server from 2014 to 2012 Changing my SQL Server type from Enterprise to Developer Switching my operating system from Windows 10 to Windows 8.1 Creating my database and it's tables again Checking my database mdf, log files access type if is Full or not, that were Full.

Aswell, I'm a administrator user. I use the same instance of SQL Server. I'm just work on this database. I connect to SQL Server using "Windows Authentication".

thank a lot for your attention

SohJel
  • 11
  • 6
  • http://stackoverflow.com/help/formatting – Soner Gönül Mar 04 '16 at 14:28
  • 3
    instead of reinstalling and downgrading everything, did you try googling the error message first? Possible duplicate of [CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105)](http://stackoverflow.com/questions/11178536/create-file-encountered-operating-system-error-5failed-to-retrieve-text-for-thi) try the two top voted answers here. – user1666620 Mar 04 '16 at 14:30
  • 4
    Read the error. "CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file" is pretty clear. SQL Server is a normal windows program - the user it is running as obviously does not have the proper permissions. Or the disc is corrupt, in read only mode or a nice little antivirus blocks the write. – TomTom Mar 04 '16 at 14:35
  • Where did you create the tables and where are you attaching them? Are these separate instances of SQL Server? I didn't understand the sentence *so that others can see it in my installed program on their computers.*. Would it possible to add more detail? – David Rushton Mar 04 '16 at 14:45
  • 1
    Make sure the service account you set up for SQL Server has access to the location you are trying to attach. It doesn't really matter if your AD account has access if the service account does not. – Steve Mangiameli Mar 04 '16 at 15:15
  • As above, check the user permissions on the MDf/LDF and make sure you are on it. – Mike Miller Mar 04 '16 at 15:31
  • I checked them and those were Access = "Full Control" for all. – SohJel Mar 04 '16 at 15:40

2 Answers2

0

Finally I did my best and solved my problem by myself with these:

I used Microsoft SQL Server Express 2014 with LocalDB for my program instead of Enterprise edition that it had Security that I didn't need it for this type of project!.

I used Microsoft Visual Studio 2015 update 1 instead of Microsoft Visual Studio 2013 update 4; I installed it(VS 2015) FULL! but this took about 3 hours!

I put my database in my project folder; I simply attatched and deattatched it in Microsoft SQL Server Express 2014 Management Studio program.

I used Microsoft Windows 8.1 instead of Windows 10, it probably was useful!

SohJel
  • 11
  • 6
0

Run SSMS as admin, do attach again.

Schonni
  • 19
  • 2
  • Hi @Schonni, can you please elaborate on your answer or provide more details if possible? Thanks! – aaossa Mar 01 '22 at 03:56