Question

I'm trying to connect to SQL DB from Server Explorer to generate context classes for Linq to SQL. Doing it like described here: http://visualcsharptutorials.com/ado-net/querying-database-linq-to-sql/

I'm getting "This file is in use." error when I try to connect. Even if I stop SQL Server in Configuration Manager I get the same error.

I can connect to DB using SSMS at the same time.

What am I doing wrong? Is it possible to connect to a DB simultaneously from VS and SSMS?

Thanks

Was it helpful?

Solution

When you say I can connect to DB using SSMS at the same time this sounds to me as if you've attached the database to SQL Server Express, and you're talking to it through its logical database name.

When you have done this (which is the best approach, in my opinion), then SQL Server (Express) is using that file and controls all access to it; you cannot just reference the .mdf file from your VS solution - you need to use the SQL Server approach and connect to the SQL Server (Express) instance and pick the database:

enter image description here

Select

  • Microsoft SQL Server (SqlClient) from the Data Source dropdown (NOT something like "database file")
  • the server name and instance you want to use (typically: .\SQLExpress - the SQLExpress instance on your local machine)
  • the database from the Select or enter a database name dropdown

  • DO NOT use anything that has to do with "attach database file" or anything like that

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top