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

吃可爱长大的小学妹 提交于 2019-12-22 18:39:21

问题


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


回答1:


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:

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



来源:https://stackoverflow.com/questions/8416301/how-to-connect-to-sql-server-express-db-from-server-explorer-vs-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!