c# - Azure - WebAPI 无法连接到 Azure DB,错误 : The system cannot find the file specified [SqlException]

标签 c# .net sql-server azure asp.net-web-api2

我有一个应用程序,分为三个部分,全部托管在 Azure 上:
(1) 客户端应用程序(HTML5、CSS3、JS),
(2) Web API,
(3) SQL Server 数据库实例。

在 Azure 上的数据库防火墙设置中启用客户端 IP 后,所有这些都在本地主机上运行,​​但是,在部署应用程序时,我从 Web API 收到以下错误:

[Win32Exception]: The system cannot find the file specified [SqlException]: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)

我尝试检查 Azure 上的防火墙设置,并且我有“允许访问 Azure 服务”,我猜测这意味着 WebAPI 服务应该有权访问数据库。

Firewall Access

我刚刚通过 SQL Server Management Studio 成功连接,并在 web.config 中使用相同的凭据。

还有什么我应该检查的吗?

最佳答案

由于您使用 ASP.Net Identity 并且在 App_Data 中有数据库,因此您也必须在 SQL Azure 中创建该数据库。

您无法在 Azure 中使用 LocalDb(位于 App_Data 文件夹内的)。通常,LocalDb 仅用于开发。

仅供引用:在 ASP.Net Identity 中,如果您的连接字符串名称碰巧与 DefaultConnection 不同,则必须重命名它也。

enter image description here

关于c# - Azure - WebAPI 无法连接到 Azure DB,错误 : The system cannot find the file specified [SqlException],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38332472/

相关文章:

sql-server - 数据库表不会删除(或显示它的输入数据)

c# - 无法使用 C# 或 VB 检索 Web 服务响应

c# - 限制进程的CPU使用率

c# - 如何从存储过程填充数据表

.net - 如何重用 GridViewColumn CellTemplate 并允许不同的绑定(bind)?

c# - .Net 桌面应用程序和 Web 应用程序之间的技术区别是什么?

c# - 如果检查两者都有值并且相等,则简化

c# - 如何在 UWP 上使用通知中心?

sql-server - 获取年份中的季度开始日期和结束日期

sql - 在 View 中使用递归 CTE