Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7421595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:26:16+00:00 2026-05-29T08:26:16+00:00

My database file Whist.mdf was attached to a SQL Server Express through Management Studio,

  • 0

My database file Whist.mdf was attached to a SQL Server Express through Management Studio, but it stopped working in that sense that NHibernate in my asp.net solution fired some connection exceptions. I just detached it from Management Studio because I couldn’t open the database in there either.

But when I try to reattach it I get this error:

Attach database failed for Server ‘MyPCName\SQLECPRESS’. (Microsoft.SqlServer.Smo) Unable to open the physical file “C:\Program
Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Whist.mdf”.
Operating system error 32: “32(process cannot access the file because
it is being used by another process)”. (Microsoft SQL Server, Error:
5120)

I have googled it but can’t find a solution that works for me. E.g.:

  • http://www.byteblocks.com/post/2010/01/06/Unable-to-open-the-physical-file-Microsoft-SQL-Server.aspx
  • "Cannot open user default database. Login failed." after installing SQL Server Management Studio Express

There is something about User Instance but I cant figure out if it have anything to do with that:

  • http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

I have tried to delete the mdf file in windows but I can’t do that either:

The action can’t be completed because the file is open in system

I have tried stopping the SQL Server process, closing explore and delete from cmd and rebooting…

Hope someone can help – I guess it is just a simple thing..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:26:17+00:00Added an answer on May 29, 2026 at 8:26 am

    I think you are on the right track. The error messages you are getting indicate that some SQL Server process is keeping the database file open. And SQL Server is designed to only allow the database file to be open by a single SQL Server process at a time.

    You are also probably right to suspect User Instance of SQL Server Express to be the guilty process here. User Instance is a special SQL Server process that doesn’t run as a service and instead is started and owned by the application that tries to connect to it. In your case there are two User Instances that can be the problem, one owned by the ASP.NET application you mentioned and one owned by you and started by Visual Studio. If you are using IIS Express or you configured the IIS App Pool for the ASP.NET application to run as your account then we only have one User Instance to worry about.

    My recommendation is that you don’t use User Instances and don’t try to connect directly to the database file. Go over your connection strings and remove User Instance=true from all of them. You want to remove AttachDBFilename=... property as well.

    If the database file is added to any of your Visual Studio solutions remove it (just be careful not to delete the file itself). The last step is to remove any connections to the database file from your Data Connections node in the Server Explorer.

    Then restart the machine to make sure any User Instances that were running in the background were shutdown. After the machine starts again you should be able to attach the database file back to your main SQL Server Express using SQL Server Management studio. Let’s name the database Whist

    To connect to your database use the following connection string:

    Data Source=.\SQLExpress;Integrated Security=true;Initial Catalog=Whist
    

    When you connect from the ASP.NET application, make sure that you have created an account in your SQL Server Express for the application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The default asp.net membership provider uses a .mdf sql server database file in the
I have a db2 database file, but do not have a db2 server. I
Is it possible to open a .mdf database file created in Visual Studio with
When I try to add a new Sql Server Database file to my Visual
I am trying to add new existing item .mdf database file created in SQL
I detach a database file from a SQL Server 2000 and try to attach
Is it possible to create an SDF database file for MS SQL Server Compact
I have a database file that is generated on a PC using Sqlite. This
I was given a MySQL database file that I need to restore as a
I'm unable to add an mdf database file by right clicking on the project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.