Error connecting to database "in file"

I am using Visual Studio 2010 C # Express and SQL Server Management Studio with SQL Server 2012. I get 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 on the Internet to try to find a solution, but no one worked. So I decided to create a completely new database and a completely new project. But I still get the error!

Here are the steps I'm using:

  • First I connected to the local server
  • then I right-clicked on Databases and selected New Database and named it school
  • then I right-clicked the tables folder in my new database and selected new table
  • I added these tables student, course, enrolled
  • finally i put some dummy entries in it

Now I turn to VS

  • I select New Project , then Windows Forms Application and name it Registrar
  • then 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 on the Microsoft SQL Server Database File to the DATA folder inside my SQLEXPRESS folder, and when I click on the school.mdf file, I get the above error.

Any help would be greatly appreciated.

+4
source share
2 answers

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

Go to your SQL Server management studio, right-click on the school, tasks, disconnect.

If it is not disconnected, it will be used by the SQL Server Management Shell.

+10
source

You need to separate it. If you do not want to do this, select "Microsoft SQL Server" instead of "Microsoft SQL Server Database File". Express versions of VB do not have Microsoft SQL Server options.

+3
source

Source: https://habr.com/ru/post/1443893/


All Articles