Visual Studio 2012 Code First still uses SQLEXPRESS by default

心不动则不痛 提交于 2019-12-05 06:12:31

All I could find was this:

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.

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

Here.

Looks like you have to actually specify (in the context constructor) that the DefaultConnection should be used by the context. For example:

public class QueensFinalDb : DbContext
{
    public QueensFinalDb()
        : base("name=DefaultConnection")
    {

    }
}

Otherwise I'm guessing it uses the first connection string in machine.config, which in my case is:

<connectionStrings>
    <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!