1

我正在关注本教程:http ://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angularjs-free-e-book/

下面是连接字符串:

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

当我尝试在命令行上运行update-database -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)

我正在尝试连接到Visual Studio 2013.

当我查看输出时:

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

这是构造函数:

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

谢谢你。

4

1 回答 1

0

我知道这已经很老了,但是我成功运行命令的方法是将 HomeCinema.Data 设置为启动项目,然后再运行 update-database -verbose 命令。我认为这是因为该命令将使用指定连接字符串的 HomeCinema.Data 项目中的 app.config。

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

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

于 2016-02-17T03:46:49.233 回答