问题
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
Databasesand selectedNew Databaseand named itschool - then i right clicked the
tablesfolder on my new database and selectednew 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 ProjectthenWindows Forms Applicationand name itRegistrar - then i click
add new data source - select
databasein theChoose a data source typewindow - then i select
Datasetin theChoose a Database Modelwindow - then I click
New ConnectionI change the DataSource toMicrosoft SQL Server Database Filebrowse 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.
回答1:
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.
回答2:
You need To detach it. If you don't want to do that, select "Microsoft SQL Server" instead of "Microsoft SQL Server Database File". Express versions VB don't have Microsoft SQL Server option.
来源:https://stackoverflow.com/questions/13215172/database-connection-error-file-in-use