默认情况下,Visual Studio 2012 Code First仍使用SQLEXPRESS [英] Visual Studio 2012 Code First still uses SQLEXPRESS by default

查看:140
本文介绍了默认情况下,Visual Studio 2012 Code First仍使用SQLEXPRESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个全新的Web API项目,创建了一个简单的Code First模型(一个具有ID和dbcontext对象的类,仅此而已),并在包管理器控制台中运行了Enable-Migrations.

I created a brand new Web API project, created a simple Code First model (one class with an id and the dbcontext object, and that's it), and ran Enable-Migrations in the package manager console.

我注意到,尽管DefaultConnection字符串指向Web.config文件中的(LocalDB),但它是在SQLEXPRESS而不是LocalDB中创建数据库的.这将导致后续查询失败,并声称该数据库尚未初始化.

I noticed that it creates the database in SQLEXPRESS rather than LocalDB, despite the DefaultConnection string pointing to (LocalDB) in the Web.config file. This causes subsequent queries to fail, claiming that the database hasn't been initialized.

如何在VS 2012中获取Enable-Migrations命令以指向LocalDB而不是SQLExpress?我尝试安装SQL Management Studio 2012 Express并停止SQLEXPRESS数据库,但这只会导致Enable-Migration命令失败.

How do I get the Enable-Migrations command in VS 2012 to point to LocalDB rather than SQLExpress? I've tried installing SQL Management Studio 2012 Express and stopping the SQLEXPRESS database, but that just causes the Enable-Migration command to fail.

有什么提示吗?

注意:我已经安装了VS 2010以及它随附的所有默认软件(例如SQL Server),所以可能是干扰.

Note: I have VS 2010 installed, along with all the default software that it comes with (like SQL Server), so perhaps that's interfering.

推荐答案

我所能找到的就是这个:

All I could find was this:

如果安装了SQL Express(包含在Visual Studio 2010中),则会在本地SQL Express实例(.\ SQLEXPRESS)上创建数据库.如果未安装SQL Express,则Code First将尝试并使用LocalDb((localdb)\ v11.0)-Visual Studio 2012中包含LocalDb.

If SQL Express is installed (included in Visual Studio 2010) then the database is created on your local SQL Express instance (.\SQLEXPRESS). If SQL Express is not installed then Code First will try and use LocalDb ((localdb)\v11.0) - LocalDb is included with Visual Studio 2012.

注意:即使安装了SQL Express,即使您使用的是Visual Studio 2012,SQL Express也会始终具有优先权.

Note: SQL Express will always get precedence if it is installed, even if you are using Visual Studio 2012

此处.

这篇关于默认情况下,Visual Studio 2012 Code First仍使用SQLEXPRESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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