MS SQL Server Express Error 5123 When Attaching a Database

I have been using MS SQL Server Management Studio Express to attach and detach my database for some time and have not had any problems until today. When I tried to attach a database, MS SQL Server Management Studio Express gave me error 5123:

Failed to retrieve data for this request. (Microsoft.SqlServer.Express.SmoEnum)

Additional Information:

CREATE FILE encountered operating system error 32(The process cannot access the file because it is being used by another process.) while attempting to open or create the physical file ‘C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xxxx.mdf’. (Microsoft SQL Server, Error:5123)

I tried the following methods but none of them could fix the problem:

  • Close out Server Management Studio Express and re-launch it to attach the database
  • Close out Server Management Studio Express and Visual Studio 2005, then re-launch Server Management Studio Express to attach the database
  • Reboot my computer
  • Completely shut down my computer
  • Restart “SQL Server (SQLEXPRESS)” service
  • Login SQL Server Management Studio Express with sa account

After several hours of trial and error, I finally figured it out. I have both MS SQL Server 2000 and SQL Server 2005 Express installed on my computer, and somehow SQL Server 2000 is holding my database which causes the above error when SQL Server 2005 Express tries to attach the same database. So I stopped “MSSQLSERVER” service (for SQL Server 2000) and “MSSQLSERVER (SQLEXPRESS)” (for SQL Server 2005 Express), restarted “MSSQLSERVER (SQLEXPRESS)”, and then launched SQL Server Management Studio Express and successfully attached my database.

My questions are: how come I didn’t have this probem before? How come SQL Server 2000 can use a SQL Server 2005 database?

10
Leave a Reply

avatar
7 Comment threads
3 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
10 Comment authors
Hankatomsciprabhualirezaksao Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
DavydDavid
Guest

I would like to see the inscription “to be continied”:-D

Sandeep Kutwal
Guest
Sandeep Kutwal

 
Windows server 2008 EE 64bit was seems having problems in security applications on the folder and file.
 
Just copy intended mdb and related log file in newly create another folder.
 
Then try to attach same mdb , you will get it work!
 
 

Luis Enrique Rodríguez Paz
Guest
Luis Enrique Rodríguez Paz

Launch the SQL Server Management Studio with administrator privileges

Alex
Guest
Alex

1. copy the db file and log file to any other folder.
2. run th SSMS (SQL Server Management Studio) with "Run as administrator"
3. attach the db.
4. enjoy 🙂

vedant
Guest
vedant

hello all,
 
1. copy the db file and log file to any other folder.
2. run th SSMS (SQL Server Management Studio) with "Run as administrator"
3. attach the db.
4. enjoy 🙂
       it's working for me,
 
  thanX guys
 

ksao
Guest
ksao

hello all,
 
1. copy the db file and log file to any other folder.
2. run th SSMS (SQL Server Management Studio) with "Run as administrator"
3. attach the db.
4. enjoy 🙂
       it's working for me,

alireza
Guest
alireza

thanks a lot

 

prabhu
Guest
prabhu

if all log and mdf file is live then i am not able copy…in this case what need to do.without stop live envoi….

atomsci
Guest
atomsci

open it on run as administrator

Hank
Guest
Hank

In SQL Server mostly the attach database error 5123 occurs at the time when you want to attach the database with the databases that are placed on different locations. Database roles also raise the error 5123, means that the detached database having different role and you are trying to attach the same with the different role. After a long research I found this helpful article here the error 5123 of attach database is described in simple words. http://sqltechtips.blogspot.com/2015/12/fix-attach-database-error-5123.html