1

我下面这个教程:http://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angularjs-free-e-book/无法连接到Visual Studio的2013的LocalDB采用了棱角分明-JS

并在下面的连接字符串:

<add name="HomeCinema" connectionString="Data Source=(LocalDb)\v11.0; 
      Initial Catalog=HomeCinema;Integrated Security=SSPI; 
      MultipleActiveResultSets=true" 
    providerName="System.Data.SqlClient" /> 

当我尝试运行最新情况:数据库-verbose在命令行,我发现了以下错误:

A network-related or instance-specific error occurred while establishing a connection to 
SQL Server. The server was not found or was not accessible. Verify that the instance name 
is correct and that SQL Server is configured to allow remote connections. 
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 

我试图连接到随附的LocalDB Visual Studio 2013

当我看到输出:

Target database is: 'HomeCinema' 
    (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention). 

这是构造:

public HomeCinemaContext() 
    : base("HomeCinema") 
{ 
    Database.SetInitializer<HomeCinemaContext>(null); 
} 

谢谢。

+0

本地数据库自带的Visual Studio 2013?它实际上会有用还是仅仅用于一些测试? –

+0

请原谅我的无知。我正在使用VS13。我在说什么localdb可以在本地访问。 – Richard77

+0

如果你仔细地点击你的项目,那么你可以添加一个数据库连接(实体或只是sql,但实体更有趣的工作)automaticaly与每一个必要的信息也automaticaly写在你的web.config –

回答

0

我知道这已经很旧了,但是我在运行update-database -verbose命令之前成功地将HomeCinema.Data设置为启动项目。我认为这是为了使命令将使用指定连接字符串的HomeCinema.Data项目中的app.config。

参考文章中的一条评论,我认为你也可以使用下面的命令。这是假设您有HomeCinema.Web作为您的启动项目,并且您的连接字符串在Web.config中设置。

更新数据库-verbose -ProjectName “HomeCinema.Data” -StartupProjectName “HomeCinema.Web” -ConnectionStringName “HomeCinema”