我有一个简单的 C# 项目。这是我在数据库的 web.config
中的连接字符串:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=172.17.0.47;Initial Catalog=DevSystemListe;User ID=web_access;Password=123456"
providerName="System.Data.SqlClient" />
</connectionStrings>
我已经确保此连接正常工作。我可以使用此连接从 Visual Studio 连接到我的数据库,我还可以看到表和数据。
当我想用 update-database
更新我的数据库时,出现了这个错误:
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)
我卸载了 Entity Framework,然后重新安装了它。什么都没有改变。
最佳答案
我终于知道了。我的解决方案中有一个网站项目和我的 API。问题是该网站被设置为启动项目。因此 Entity Framework 在网站的 web.config
中搜索连接字符串,而不是在 api 的 web.config
中搜索。将启动项目更改为我的 API 解决了问题。
如果你想将网站项目作为启动项目。只需将连接字符串复制到网站 web.config
即可。
不过还是感谢大家的帮助。
关于c# - 更新数据库 : "A network-related or instance-specific error occurred while establishing a connection to SQL Server",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31264575/