Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

sql server - Database Connection Error "file in use"

I am using Visual Studio 2010 C# Express and SQL Server Management Studio with SQL Server 2012 I am getting an error when I try to connect a database to my Windows forms project.

"This file is in use.  Enter a new name or
close the file that is open in another program"

I poked around online to try to find a solution but none worked. So i decided to create a brand new database and a brand new project. But I still get the error!

here are the steps I use:

  • First I connected to my locally hosted server
  • then i right-clicked on Databases and selected New Database and named it school
  • then i right clicked the tables folder on my new database and selected new table
  • I added thes tables student, course, enrolled
  • finally i threw some bogus entries into it

Now I jump over to VS

  • I select New Project then Windows Forms Application and name it Registrar
  • then i click add new data source
  • select database in the Choose a data source type window
  • then i select Dataset in the Choose a Database Model window
  • then I click New Connection I change the DataSource to Microsoft SQL Server Database File browse to the DATA folder inside my 'SQLEXPRESS' folder and when i click the 'school.mdf' file i get the above error.

any help would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your school.mdf is attached in your SQL Server 2012. You need to detach it.

Go to your SQL Server Management Studio, Right-Click on School, Tasks, Detach.

Unless it is detached, it will be in use by the the SQL Server Management Studio.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...