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的步骤是什么?
在Visual Studio 2012中,我所要做的就是输入:
(localdb)\v11.0
Visual Studio 2015和Visual Studio 2017更改为:
(localdb)\MSSQLLocalDB
添加Microsoft SQL server数据源时,将其作为服务器名:
View/Server Explorer/(Right click) Data Connections/Add Connection
然后填充数据库名称。我不需要在接受的答案中执行所有其他步骤,尽管如果服务器名称在服务器名称组合框中自动可用就更好了。
您还可以使用以下命令浏览机器上可用的LocalDB数据库名称:
View/SQL Server Object Explorer.
场景: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(点击刷新)
连接到数据库:在下拉菜单中选择新数据库。
我希望这能有所帮助。