如何从Server Explorer VS 2010连接到SQL Server Express DB? [英] How to connect to SQL Server Express DB from Server Explorer VS 2010?

查看:133
本文介绍了如何从Server Explorer VS 2010连接到SQL Server Express DB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从服务器资源管理器连接到SQL DB,以生成用于Linq to SQL的上下文类.按照此处所述进行操作: http://visualcsharptutorials.com/ado- net/querying-database-linq-to-sql/

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/

我收到此文件正在使用中".尝试连接时出现错误.即使在配置管理器中停止SQL Server,我也会遇到相同的错误.

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.

我可以同时使用SSMS连接到数据库.

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

我做错了什么?是否可以同时从VS和SSMS连接到DB?

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

谢谢

推荐答案

当您说我可以同时使用SSMS连接到数据库时,这听起来像是您已附加数据库到SQL Server Express,您正在通过其逻辑数据库名称与之对话.

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.

完成此操作(我认为这是最好的方法),然后SQL Server(Express)使用该文件并控制对该文件的所有访问;您不能仅引用VS解决方案中的.mdf文件-您需要使用 SQL Server 方法并连接到SQL Server(Express)实例并选择数据库:

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:

选择

    Data Source下拉菜单中的
  • Microsoft SQL Server (SqlClient)(类似于数据库文件")
  • 您要使用的服务器名称和实例(通常是:.\SQLExpress-您本地计算机上的SQLExpress实例)
  • Select or enter a database name下拉列表中的数据库

  • 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

这篇关于如何从Server Explorer VS 2010连接到SQL Server Express DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆