update-database失败,错误0x80131904(找不到服务器)

时间:2017-02-10 20:15:01

标签: c# asp.net-mvc

我的应用程序有连接字符串

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

在库XXX.Data中。但是当在PMC中启动命令update-database时,将显示错误:

Target database is: 'XXX' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
System.Data.SqlClient.SqlException (0x80131904): 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)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)

尝试连接到.\SQLEXPRESS而不是(LocalDb)\v14.0;Initial Catalog=XXX?为什么呢?

我在任何dll文件中都没有任何其他连接字符串。

更新1: 我尝试了其他连接字符串,但它也失败了:

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

1 个答案:

答案 0 :(得分:2)

  1. 我不得不卸载包含EF的xxx.web项目,但它没有连接字符串。

  2. 在步骤1之后,它适用于具有2个参数的以下命令:

    update-database -ConnectionStringName "XXX" -ProjectName "XXXX.Data"