如何在Visual Studio Server Explorer中连接到LocalDB ?

时间:2022-06-05 02:49:02

I can't believe I couldn't find a working solution to this after an hour of searching. I'm following this article on Entity Framework 6.0 which gives a simple walk-through on Code First. I created the project and installed the latest EF Nuget package for the project to compile. I also verified that I have Microsoft SQL Server 2012 Express LocalDB installed which came with Visual Studio 2013. I don't have any other instances of SQL installed on my local computer. The program runs and entries are added to the database and outputted in the console. But when the article says "check your localdb" it doesn't say how! I don't see any '.mdf' or '.ldf' files created under the project folder. I tried every way to connect Visual Studio's Server Explorer to LocalDB. The wizard cannot locate (localdb) or cannot find any provider in Server Explorer to accept connection string like (localdb)\v11.0;Integrated Security=true; I've seen this asked several places in * but no answer works or marked as answer. Please help, this doesn't have to be this frustrating!

我真不敢相信,经过一个小时的搜寻,我竟然找不到一个有效的解决方案。我正在跟踪这篇关于实体框架6.0的文章,它首先简单地介绍了代码。我创建了这个项目,并安装了最新的EF Nuget包来编译这个项目。我还验证了我已经安装了Microsoft SQL Server 2012 Express LocalDB,它是与Visual Studio 2013一起安装的。我没有在本地计算机上安装任何其他SQL实例。程序运行和条目被添加到数据库中并在控制台中输出。但是当文章说“检查你的localdb”时,它并没有说“如何”!我什么也没看见。mdf’或‘。在项目文件夹下创建的ldf文件。我尝试了各种方法将Visual Studio的服务器资源管理器连接到LocalDB。向导无法定位(localdb)或无法在服务器资源管理器中找到任何提供者,以接受类似(localdb)\v11.0的连接字符串;集成安全性=true;我曾见过在*的几个地方,但没有答案,也没有答案。请帮忙,这并不一定会让人沮丧!

What are the steps to connect Visual Studio Server Explorer to LocalDB?

将Visual Studio Server Explorer连接到LocalDB的步骤是什么?

13 个解决方案

#1


227  

OK, answering to my own question.

好的,回答我自己的问题。

Steps to connect LocalDB to Visual Studio Server Explorer

将LocalDB连接到Visual Studio Server Explorer的步骤。

  1. Open command prompt
  2. 打开命令提示符
  3. Run SqlLocalDB.exe start v11.0
  4. SqlLocalDB运行。exe开始v11.0
  5. Run SqlLocalDB.exe info v11.0
  6. SqlLocalDB运行。exe信息v11.0
  7. Copy the Instance pipe name that starts with np:\...
  8. 复制以np开始的实例管道名称:\…
  9. In Visual Studio select TOOLS > Connect to Database...
  10. 在Visual Studio中选择工具>连接到数据库…
  11. For Server Name enter (localdb)\v11.0. If it didn't work, use the Instance pipe name that you copied earlier. You can also use this to connect with SQL Management Studio.
  12. 对于服务器名输入(localdb)\v11.0。如果它不起作用,请使用您先前复制的实例管道名称。您还可以使用它连接SQL管理Studio。
  13. Select the database on next dropdown list
  14. 在下一个下拉列表中选择数据库。
  15. Click OK
  16. 单击OK

如何在Visual Studio Server Explorer中连接到LocalDB ?

#2


212  

In Visual Studio 2012 all I had to do was enter:

在Visual Studio 2012中,我只需要输入:

(localdb)\v11.0

Visual Studio 2015 and Visual Studio 2017 changed to:

Visual Studio 2015和Visual Studio 2017更改为:

(localdb)\MSSQLLocalDB

as the server name when adding a Microsoft SQL Server Data source in:

在添加Microsoft SQL server数据源时,作为服务器名:

View/Server Explorer/(Right click) Data Connections/Add Connection

and then the database names were populated. I didn't need to do all the other steps in the accepted answer, although it would be nice if the server name was available automatically in the server name combo box.

然后填充数据库名。我不需要在接受的答案中做所有其他的步骤,虽然如果服务器名称在服务器名称组合框中是自动可用的,那就更好了。

You can also browse the LocalDB database names available on your machine using:

您还可以在您的机器上浏览LocalDB数据库名称:

View/SQL Server Object Explorer.

#3


54  

Select in :

选择:

  1. Data Source: Microsoft SQL Server (SqlClient)
  2. 数据源:Microsoft SQL Server (SqlClient)
  3. Server name: (localdb)\MSSQLLocalDB
  4. 服务器名称:(localdb)\ MSSQLLocalDB
  5. Log on to the server: Use Windows Authentication
  6. 登录服务器:使用Windows身份验证。

Press Refresh button to get the database name :)

按Refresh按钮获取数据库名称:)

如何在Visual Studio Server Explorer中连接到LocalDB ?

#4


14  

It worked for me.

它为我工作。

  1. Open command prompt
  2. 打开命令提示符
  3. Run "SqlLocalDB.exe start"
  4. “SqlLocalDB运行。exe开始”
  5. System response "LocalDB instance "mssqllocaldb" started."
  6. 系统响应“LocalDB实例”mssqllocaldb“启动”。
  7. In VS, View/Server Explorer/(Right click) Data Connections/Add Connection
    • Data Source: Microsoft SQL Server (SqlClient)
    • 数据源:Microsoft SQL Server (SqlClient)
    • Server name: (localdb)\MSSQLLocalDB
    • 服务器名称:(localdb)\ MSSQLLocalDB
    • Log on to the server: Use Windows Authentication
    • 登录服务器:使用Windows身份验证。
  8. 在VS,Server Explorer视图/ /(右键)数据连接/添加连接数据源:Microsoft SQL Server(SqlClient)服务器名称:(localdb)\ MSSQLLocalDB登录到服务器:使用Windows身份验证
  9. Press "Test Connection", Then OK.
  10. 按“测试连接”,然后OK。

#5


7  

Visual Studio 2015 RC, has LocalDb 12 installed, similar instructions to before but still shouldn't be required to know 'magic', before hand to use this, the default instance should have been turned on ... Rant complete, no for solution:

Visual Studio 2015 RC,已经安装了LocalDb 12,类似的指令,但是仍然不需要知道“魔法”,在使用这个之前,默认的实例应该是打开的。咆哮完成,不为解决:

cmd> sqllocaldb start

Which will display

这将显示

LocalDB instance "MSSQLLocalDB" started.

Your instance name might differ. Either way pop over to VS and open Server Explorer, right click Data Connections, choose Add, choose SQL Server, in the server name type:

您的实例名可能不同。无论哪种方式,都可以切换到VS和open Server Explorer,右键单击数据连接,选择Add,选择SQL Server,在服务器名称类型中:

(localdb)\MSSQLLocalDB

Without entering in a DB name, click 'Test Connection'.

如果不输入DB名称,请单击“Test Connection”。

#6


7  

The following works with Visual Studio 2017 Community Edition on Windows 10 using SQLServer Express 2016.

以下是使用SQLServer Express 2016版Windows 10的Visual Studio 2017 Community Edition。

Open a PowerShell check what it is called using SqlLocalDB.exe info and whether it is Running with SqlLocalDB.exe info NAME. Here's what it looks like on my machine:

打开一个PowerShell,使用SqlLocalDB来检查它的名称。exe信息,以及它是否运行SqlLocalDB。exe信息的名字。这是我机器上的样子:

> SqlLocalDB.exe info
MSSQLLocalDB
> SqlLocalDB.exe info MSSQLLocalDB
Name:               mssqllocaldb
Version:            13.0.1601.5
Shared name:
Owner:              DESKTOP-I4H3E09\simon
Auto-create:        Yes
State:              Running
Last start time:    4/12/2017 8:24:36 AM
Instance pipe name: np:\\.\pipe\LOCALDB#EFC58609\tsql\query
>

If it isn't running then you need to start it with SqlLocalDB.exe start MSSQLLocalDB. When it is running you see the Instance pipe name: which starts with np:\\. Copy that named pipe string. Within VS2017 open the view Server Explorer and create a new connection of type Microsoft SQL Server (SqlClient) (don't be fooled by the other file types you want the full fat connection type) and set the Server name: to be the instance pipe name you copied from PowerShell.

如果它没有运行,那么您需要使用SqlLocalDB启动它。exe MSSQLLocalDB开始。当它运行时,您可以看到实例管道名称:它从np开始:\\。复制命名管道字符串。在VS2017中打开视图服务器资源管理器并创建一个新连接的Microsoft SQL Server (SqlClient)(不要被其他文件类型所欺骗,您需要全fat连接类型)并设置服务器名称:作为从PowerShell中复制的实例管道名称。

I also set the Connect to database to be the same database that was in the connection string that was working in my Dotnet Core / Entity Framework Core project which was set up using dotnet ef database update.

我还将连接数据库设置为与在我的Dotnet核心/实体框架核心项目中工作的连接字符串相同的数据库,该项目是使用Dotnet ef数据库更新设置的。

You can login and create a database using the sqlcmd and the named pipe string:

您可以使用sqlcmd和命名管道字符串登录和创建数据库:

sqlcmd -S np:\\.\pipe\LOCALDB#EFC58609\tsql\query 1> create database EFGetStarted.ConsoleApp.NewDb; 2> GO

sqlcmd - s np:\ \。\pipe\LOCALDB#EFC58609\tsql\query 1>创建数据库efgetstar. consoleapp . newdb;2 >去

There are instructions on how to create a user for your application at https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility

在https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility中,有关于如何为您的应用程序创建用户的说明。

#7


5  

Fix doesn't work.

修复是行不通的。

Exactly as in the example illustration, all these steps only provide access to "system" databases, and no option to select existing user databases that you want to access.

就像在示例演示中一样,所有这些步骤只提供对“系统”数据库的访问,并且没有选择您想要访问的现有用户数据库的选项。

The solution to access a local (not Express Edition) Microsoft SQL server instance resides on the SQL Server side:

访问本地(非Express Edition) Microsoft SQL服务器实例的解决方案驻留在SQL server端:

  1. Open the Run dialog (WinKey + R)
  2. 打开运行对话框(WinKey + R)
  3. Type: "services.msc"
  4. 类型:“services.msc”
  5. Select SQL Server Browser
  6. 选择SQL服务器浏览器
  7. Click Properties
  8. 单击“属性”
  9. Change "disabled" to either "Manual" or "Automatic"
  10. 将“禁用”改为“手动”或“自动”
  11. When the "Start" service button gets enable, click on it.
  12. 当“启动”服务按钮启用时,单击它。

Done! Now you can select your local SQL Server from the Server Name list in Connection Properties.

完成了!现在可以从连接属性的服务器名列表中选择本地SQL服务器。

#8


5  

Use SQL Server Object Explorer (SSOX) Instead

  • From the View menu, open SQL Server Object Explorer.
  • 从视图菜单中打开SQL Server对象资源管理器。

如何在Visual Studio Server Explorer中连接到LocalDB ?

  • Right click on the {YourTableName} table > View Designer
  • 右击{YourTableName}表>视图设计器。

如何在Visual Studio Server Explorer中连接到LocalDB ?

#9


3  

Run the CMD as admin.

运行CMD作为admin。

  1. from start menu 'cmd' - wait for it to find it.
  2. 从开始菜单的cmd -等待它找到它。
  3. Right click on cmd, and select open as administrator
  4. 右键单击cmd,并选择open作为管理员。
  5. type : cd C:\Program Files\Microsoft SQL Server\120\Tools\Binn
  6. 类型:cd c:)程序文件,微软SQL Server\120\Tools\Binn。
  7. type : SqlLocalDB start
  8. 类型:SqlLocalDB开始
  9. now type : SqlLocalDB info
  10. 现在输入:SqlLocalDB信息。
  11. Shows the running sql instances available... choose what you want...
  12. 显示可用的运行sql实例…选择你想要的…
  13. to find more about the instance type : SqlLocalDB info instanceName

    要找到更多关于实例类型的信息:SqlLocalDB info instanceName。

  14. now from VS you can setup your connection In VS, View/Server Explorer/(Right click) Data Connections/Add Connection Data Source: Microsoft SQL Server (SqlClient) Server name: (localdb)\MSSQLLocalDB Log on to the server: Use Windows Authentication Press "Test Connection", Then OK.

    从和你可以设置连接在VS Server Explorer视图/ /(右键)数据连接/添加连接数据源:Microsoft SQL Server(SqlClient)服务器名称:(localdb)\ MSSQLLocalDB登录到服务器:使用Windows身份验证按“测试连接”,然后点击OK。

  15. job done

    完成工作

#10


3  

The fastest way in Visual Studio 2017 is to go to Tools -> SQL Server -> New query.. Choose from Local databases and choose the desired Database name at the bottom.

在Visual Studio 2017中最快的方法是使用工具-> SQL Server ->新查询。从本地数据库中选择并在底部选择所需的数据库名称。

Alternative way

替代方法

Visual Studio 2017 Server name is:

Visual Studio 2017服务器名称为:

(localdb)\MSSQLLocalDB

Add the new connection using menu Tools -> Connect to Database...

添加新的连接使用菜单工具->连接到数据库…

#11


1  

I followed the steps above, but I forgot to install the SQL Server 2014 LocalDB before the Visual Studio 2015 configuration.

我遵循上面的步骤,但是我忘记在Visual Studio 2015配置之前安装SQL Server 2014 LocalDB。

My steps are as follow:

我的步骤如下:

  1. Install the SQL Server 2014 LocalDB;
  2. 安装SQL Server 2014 LocalDB;
  3. Open Visual Studio 2015 and then SQL Server Object Explorer;
  4. 开放Visual Studio 2015,然后是SQL Server对象资源管理器;
  5. Find your LocalDB under the SQL Server tag.
  6. 在SQL Server标记下找到LocalDB。

Hope this help anybody.

希望这帮助任何人。

#12


0  

Scenario: Windows 8.1, VS2013 Ultimate, SQL Express Installed and running, SQL Server Browser Disabled. This worked for me:

场景:Windows 8.1, VS2013 Ultimate, SQL Express安装和运行,SQL Server浏览器禁用。这工作对我来说:

  1. First I enabled SQL Server Browser under services.
  2. 首先,我在服务中启用了SQL Server浏览器。
  3. In Visual Studio: Open the Package Manager Console then type: Enable-Migrations; Then Type Enable-Migrations -ContextTypeName YourContextDbName that created the Migrations folder in VS.
  4. 在Visual Studio中:打开包管理器控制台,然后输入:Enable-Migrations;然后,在VS中创建Migrations文件夹,然后输入Enable-Migrations - context - pename YourContextDbName。
  5. Inside the Migrations folder you will find the "Configuration.cs" file, turn on automatic migrations by: AutomaticMigrationsEnabled = true;
  6. 在Migrations文件夹中,您将找到“配置”。cs“文件,打开自动迁移:自动迁移senabled = true;
  7. Run your application again, the environment creates a DefaultConnection and you will see the new tables from your context. This new connection points to the localdb. The created connection string shows: Data Source=(LocalDb)\v11.0 ... (more parameters and path to the created mdf file)
  8. 再次运行您的应用程序,环境创建一个DefaultConnection,您将从上下文看到新的表。这个新的连接指向localdb。创建的连接字符串显示:Data Source=(LocalDb)\v11.0…(创建mdf文件的更多参数和路径)

You can now create a new connection with Server name: (LocalDb)\v11.0 (hit refresh) Connect to a database: Select your new database under the dropdown.

现在可以创建一个与服务器名称的新连接:(LocalDb)\v11.0(单击刷新)连接到数据库:在下拉菜单下选择新数据库。

I hope it helps.

我希望它有帮助。

#13


0  

With SQL Server 2017 and Visual Studio 2015, I used localhost\SQLEXPRESS

使用SQL Server 2017和Visual Studio 2015,我使用了localhost\SQLEXPRESS。

如何在Visual Studio Server Explorer中连接到LocalDB ?

#1


227  

OK, answering to my own question.

好的,回答我自己的问题。

Steps to connect LocalDB to Visual Studio Server Explorer

将LocalDB连接到Visual Studio Server Explorer的步骤。

  1. Open command prompt
  2. 打开命令提示符
  3. Run SqlLocalDB.exe start v11.0
  4. SqlLocalDB运行。exe开始v11.0
  5. Run SqlLocalDB.exe info v11.0
  6. SqlLocalDB运行。exe信息v11.0
  7. Copy the Instance pipe name that starts with np:\...
  8. 复制以np开始的实例管道名称:\…
  9. In Visual Studio select TOOLS > Connect to Database...
  10. 在Visual Studio中选择工具>连接到数据库…
  11. For Server Name enter (localdb)\v11.0. If it didn't work, use the Instance pipe name that you copied earlier. You can also use this to connect with SQL Management Studio.
  12. 对于服务器名输入(localdb)\v11.0。如果它不起作用,请使用您先前复制的实例管道名称。您还可以使用它连接SQL管理Studio。
  13. Select the database on next dropdown list
  14. 在下一个下拉列表中选择数据库。
  15. Click OK
  16. 单击OK

如何在Visual Studio Server Explorer中连接到LocalDB ?

#2


212  

In Visual Studio 2012 all I had to do was enter:

在Visual Studio 2012中,我只需要输入:

(localdb)\v11.0

Visual Studio 2015 and Visual Studio 2017 changed to:

Visual Studio 2015和Visual Studio 2017更改为:

(localdb)\MSSQLLocalDB

as the server name when adding a Microsoft SQL Server Data source in:

在添加Microsoft SQL server数据源时,作为服务器名:

View/Server Explorer/(Right click) Data Connections/Add Connection

and then the database names were populated. I didn't need to do all the other steps in the accepted answer, although it would be nice if the server name was available automatically in the server name combo box.

然后填充数据库名。我不需要在接受的答案中做所有其他的步骤,虽然如果服务器名称在服务器名称组合框中是自动可用的,那就更好了。

You can also browse the LocalDB database names available on your machine using:

您还可以在您的机器上浏览LocalDB数据库名称:

View/SQL Server Object Explorer.

#3


54  

Select in :

选择:

  1. Data Source: Microsoft SQL Server (SqlClient)
  2. 数据源:Microsoft SQL Server (SqlClient)
  3. Server name: (localdb)\MSSQLLocalDB
  4. 服务器名称:(localdb)\ MSSQLLocalDB
  5. Log on to the server: Use Windows Authentication
  6. 登录服务器:使用Windows身份验证。

Press Refresh button to get the database name :)

按Refresh按钮获取数据库名称:)

如何在Visual Studio Server Explorer中连接到LocalDB ?

#4


14  

It worked for me.

它为我工作。

  1. Open command prompt
  2. 打开命令提示符
  3. Run "SqlLocalDB.exe start"
  4. “SqlLocalDB运行。exe开始”
  5. System response "LocalDB instance "mssqllocaldb" started."
  6. 系统响应“LocalDB实例”mssqllocaldb“启动”。
  7. In VS, View/Server Explorer/(Right click) Data Connections/Add Connection
    • Data Source: Microsoft SQL Server (SqlClient)
    • 数据源:Microsoft SQL Server (SqlClient)
    • Server name: (localdb)\MSSQLLocalDB
    • 服务器名称:(localdb)\ MSSQLLocalDB
    • Log on to the server: Use Windows Authentication
    • 登录服务器:使用Windows身份验证。
  8. 在VS,Server Explorer视图/ /(右键)数据连接/添加连接数据源:Microsoft SQL Server(SqlClient)服务器名称:(localdb)\ MSSQLLocalDB登录到服务器:使用Windows身份验证
  9. Press "Test Connection", Then OK.
  10. 按“测试连接”,然后OK。

#5


7  

Visual Studio 2015 RC, has LocalDb 12 installed, similar instructions to before but still shouldn't be required to know 'magic', before hand to use this, the default instance should have been turned on ... Rant complete, no for solution:

Visual Studio 2015 RC,已经安装了LocalDb 12,类似的指令,但是仍然不需要知道“魔法”,在使用这个之前,默认的实例应该是打开的。咆哮完成,不为解决:

cmd> sqllocaldb start

Which will display

这将显示

LocalDB instance "MSSQLLocalDB" started.

Your instance name might differ. Either way pop over to VS and open Server Explorer, right click Data Connections, choose Add, choose SQL Server, in the server name type:

您的实例名可能不同。无论哪种方式,都可以切换到VS和open Server Explorer,右键单击数据连接,选择Add,选择SQL Server,在服务器名称类型中:

(localdb)\MSSQLLocalDB

Without entering in a DB name, click 'Test Connection'.

如果不输入DB名称,请单击“Test Connection”。

#6


7  

The following works with Visual Studio 2017 Community Edition on Windows 10 using SQLServer Express 2016.

以下是使用SQLServer Express 2016版Windows 10的Visual Studio 2017 Community Edition。

Open a PowerShell check what it is called using SqlLocalDB.exe info and whether it is Running with SqlLocalDB.exe info NAME. Here's what it looks like on my machine:

打开一个PowerShell,使用SqlLocalDB来检查它的名称。exe信息,以及它是否运行SqlLocalDB。exe信息的名字。这是我机器上的样子:

> SqlLocalDB.exe info
MSSQLLocalDB
> SqlLocalDB.exe info MSSQLLocalDB
Name:               mssqllocaldb
Version:            13.0.1601.5
Shared name:
Owner:              DESKTOP-I4H3E09\simon
Auto-create:        Yes
State:              Running
Last start time:    4/12/2017 8:24:36 AM
Instance pipe name: np:\\.\pipe\LOCALDB#EFC58609\tsql\query
>

If it isn't running then you need to start it with SqlLocalDB.exe start MSSQLLocalDB. When it is running you see the Instance pipe name: which starts with np:\\. Copy that named pipe string. Within VS2017 open the view Server Explorer and create a new connection of type Microsoft SQL Server (SqlClient) (don't be fooled by the other file types you want the full fat connection type) and set the Server name: to be the instance pipe name you copied from PowerShell.

如果它没有运行,那么您需要使用SqlLocalDB启动它。exe MSSQLLocalDB开始。当它运行时,您可以看到实例管道名称:它从np开始:\\。复制命名管道字符串。在VS2017中打开视图服务器资源管理器并创建一个新连接的Microsoft SQL Server (SqlClient)(不要被其他文件类型所欺骗,您需要全fat连接类型)并设置服务器名称:作为从PowerShell中复制的实例管道名称。

I also set the Connect to database to be the same database that was in the connection string that was working in my Dotnet Core / Entity Framework Core project which was set up using dotnet ef database update.

我还将连接数据库设置为与在我的Dotnet核心/实体框架核心项目中工作的连接字符串相同的数据库,该项目是使用Dotnet ef数据库更新设置的。

You can login and create a database using the sqlcmd and the named pipe string:

您可以使用sqlcmd和命名管道字符串登录和创建数据库:

sqlcmd -S np:\\.\pipe\LOCALDB#EFC58609\tsql\query 1> create database EFGetStarted.ConsoleApp.NewDb; 2> GO

sqlcmd - s np:\ \。\pipe\LOCALDB#EFC58609\tsql\query 1>创建数据库efgetstar. consoleapp . newdb;2 >去

There are instructions on how to create a user for your application at https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility

在https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility中,有关于如何为您的应用程序创建用户的说明。

#7


5  

Fix doesn't work.

修复是行不通的。

Exactly as in the example illustration, all these steps only provide access to "system" databases, and no option to select existing user databases that you want to access.

就像在示例演示中一样,所有这些步骤只提供对“系统”数据库的访问,并且没有选择您想要访问的现有用户数据库的选项。

The solution to access a local (not Express Edition) Microsoft SQL server instance resides on the SQL Server side:

访问本地(非Express Edition) Microsoft SQL服务器实例的解决方案驻留在SQL server端:

  1. Open the Run dialog (WinKey + R)
  2. 打开运行对话框(WinKey + R)
  3. Type: "services.msc"
  4. 类型:“services.msc”
  5. Select SQL Server Browser
  6. 选择SQL服务器浏览器
  7. Click Properties
  8. 单击“属性”
  9. Change "disabled" to either "Manual" or "Automatic"
  10. 将“禁用”改为“手动”或“自动”
  11. When the "Start" service button gets enable, click on it.
  12. 当“启动”服务按钮启用时,单击它。

Done! Now you can select your local SQL Server from the Server Name list in Connection Properties.

完成了!现在可以从连接属性的服务器名列表中选择本地SQL服务器。

#8


5  

Use SQL Server Object Explorer (SSOX) Instead

  • From the View menu, open SQL Server Object Explorer.
  • 从视图菜单中打开SQL Server对象资源管理器。

如何在Visual Studio Server Explorer中连接到LocalDB ?

  • Right click on the {YourTableName} table > View Designer
  • 右击{YourTableName}表>视图设计器。

如何在Visual Studio Server Explorer中连接到LocalDB ?

#9


3  

Run the CMD as admin.

运行CMD作为admin。

  1. from start menu 'cmd' - wait for it to find it.
  2. 从开始菜单的cmd -等待它找到它。
  3. Right click on cmd, and select open as administrator
  4. 右键单击cmd,并选择open作为管理员。
  5. type : cd C:\Program Files\Microsoft SQL Server\120\Tools\Binn
  6. 类型:cd c:)程序文件,微软SQL Server\120\Tools\Binn。
  7. type : SqlLocalDB start
  8. 类型:SqlLocalDB开始
  9. now type : SqlLocalDB info
  10. 现在输入:SqlLocalDB信息。
  11. Shows the running sql instances available... choose what you want...
  12. 显示可用的运行sql实例…选择你想要的…
  13. to find more about the instance type : SqlLocalDB info instanceName

    要找到更多关于实例类型的信息:SqlLocalDB info instanceName。

  14. now from VS you can setup your connection In VS, View/Server Explorer/(Right click) Data Connections/Add Connection Data Source: Microsoft SQL Server (SqlClient) Server name: (localdb)\MSSQLLocalDB Log on to the server: Use Windows Authentication Press "Test Connection", Then OK.

    从和你可以设置连接在VS Server Explorer视图/ /(右键)数据连接/添加连接数据源:Microsoft SQL Server(SqlClient)服务器名称:(localdb)\ MSSQLLocalDB登录到服务器:使用Windows身份验证按“测试连接”,然后点击OK。

  15. job done

    完成工作

#10


3  

The fastest way in Visual Studio 2017 is to go to Tools -> SQL Server -> New query.. Choose from Local databases and choose the desired Database name at the bottom.

在Visual Studio 2017中最快的方法是使用工具-> SQL Server ->新查询。从本地数据库中选择并在底部选择所需的数据库名称。

Alternative way

替代方法

Visual Studio 2017 Server name is:

Visual Studio 2017服务器名称为:

(localdb)\MSSQLLocalDB

Add the new connection using menu Tools -> Connect to Database...

添加新的连接使用菜单工具->连接到数据库…

#11


1  

I followed the steps above, but I forgot to install the SQL Server 2014 LocalDB before the Visual Studio 2015 configuration.

我遵循上面的步骤,但是我忘记在Visual Studio 2015配置之前安装SQL Server 2014 LocalDB。

My steps are as follow:

我的步骤如下:

  1. Install the SQL Server 2014 LocalDB;
  2. 安装SQL Server 2014 LocalDB;
  3. Open Visual Studio 2015 and then SQL Server Object Explorer;
  4. 开放Visual Studio 2015,然后是SQL Server对象资源管理器;
  5. Find your LocalDB under the SQL Server tag.
  6. 在SQL Server标记下找到LocalDB。

Hope this help anybody.

希望这帮助任何人。

#12


0  

Scenario: Windows 8.1, VS2013 Ultimate, SQL Express Installed and running, SQL Server Browser Disabled. This worked for me:

场景:Windows 8.1, VS2013 Ultimate, SQL Express安装和运行,SQL Server浏览器禁用。这工作对我来说:

  1. First I enabled SQL Server Browser under services.
  2. 首先,我在服务中启用了SQL Server浏览器。
  3. In Visual Studio: Open the Package Manager Console then type: Enable-Migrations; Then Type Enable-Migrations -ContextTypeName YourContextDbName that created the Migrations folder in VS.
  4. 在Visual Studio中:打开包管理器控制台,然后输入:Enable-Migrations;然后,在VS中创建Migrations文件夹,然后输入Enable-Migrations - context - pename YourContextDbName。
  5. Inside the Migrations folder you will find the "Configuration.cs" file, turn on automatic migrations by: AutomaticMigrationsEnabled = true;
  6. 在Migrations文件夹中,您将找到“配置”。cs“文件,打开自动迁移:自动迁移senabled = true;
  7. Run your application again, the environment creates a DefaultConnection and you will see the new tables from your context. This new connection points to the localdb. The created connection string shows: Data Source=(LocalDb)\v11.0 ... (more parameters and path to the created mdf file)
  8. 再次运行您的应用程序,环境创建一个DefaultConnection,您将从上下文看到新的表。这个新的连接指向localdb。创建的连接字符串显示:Data Source=(LocalDb)\v11.0…(创建mdf文件的更多参数和路径)

You can now create a new connection with Server name: (LocalDb)\v11.0 (hit refresh) Connect to a database: Select your new database under the dropdown.

现在可以创建一个与服务器名称的新连接:(LocalDb)\v11.0(单击刷新)连接到数据库:在下拉菜单下选择新数据库。

I hope it helps.

我希望它有帮助。

#13


0  

With SQL Server 2017 and Visual Studio 2015, I used localhost\SQLEXPRESS

使用SQL Server 2017和Visual Studio 2015,我使用了localhost\SQLEXPRESS。

如何在Visual Studio Server Explorer中连接到LocalDB ?