linqsql-server-2008visual-studio-2010sql-server-2008-expressserver-explorer

How to connect to SQL Server Express DB from Server Explorer VS 2010?


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


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