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 StackOverflow but no answer works or marked as answer. Please help, this doesn't have to be this frustrating!

连接Visual Studio服务器资源管理器到LocalDB的步骤是什么?


当前回答

以admin用户运行CMD。

from start menu 'cmd' - wait for it to find it. Right click on cmd, and select open as administrator type : cd C:\Program Files\Microsoft SQL Server\120\Tools\Binn type : SqlLocalDB start now type : SqlLocalDB info Shows the running sql instances available... choose what you want... to find more about the instance type : SqlLocalDB info instanceName 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. job done

其他回答

场景:Windows 8.1, VS2013 Ultimate, SQL Express已安装并运行,SQL Server浏览器已禁用。 这招对我很管用:

First I enabled SQL Server Browser under services. 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. Inside the Migrations folder you will find the "Configuration.cs" file, turn on automatic migrations by: AutomaticMigrationsEnabled = true; 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)

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

我希望这能有所帮助。

选择在:

数据来源:Microsoft SQL Server (SqlClient) 服务器名称:(localdb)\MSSQLLocalDB 登录服务器:使用Windows身份验证

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

修理不起作用。

与示例插图中一样,所有这些步骤都只提供对“系统”数据库的访问,而没有选择要访问的现有用户数据库的选项。

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

打开运行对话框(WinKey + R) 类型:“services.msc” 选择SQL Server浏览器 单击“属性” 将“禁用”改为“手动”或“自动” 当“Start”服务按钮启用时,单击它。

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

以下是使用SQLServer Express 2016在Windows 10上使用Visual Studio 2017 Community Edition进行的工作。

打开一个PowerShell,使用SqlLocalDB.exe info检查它的名称,以及它是否使用SqlLocalDB.exe info NAME运行。下面是它在我的机器上的样子:

> 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
>

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

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

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

sqlcmd -S np:\\.\pipe\ localdb# EFC58609\tsql\query 创建数据库EFGetStarted.ConsoleApp.NewDb; 2 >

https://learn.microsoft.com/en-us/sql/tools/sqllocaldb-utility上有关于如何为应用程序创建用户的说明

请使用SQL Server对象资源管理器(SSOX)

与其他答案不同,这种方法使用: —无特殊命令。 —无复杂配置。 只需使用SQL Server对象资源管理器

这很简单……

从“视图”菜单中,打开SQL Server对象资源管理器。

右击{YourTableName}表>视图设计器

完成了。