Skip to main content
 首页 » 编程设计

c#之从 Azure Web 应用程序连接到 On Prem SQL 服务器

2024年01月18日33zhoujg

我在 prim 有 .Net 应用程序。我想在 Azure 上托管它,但不想移动数据库。我在 Azure 上发布了应用程序,但它无法连接到 prim 数据库。

SQL 服务器在专用网络中。

出于 POC 目的,我正在使用 MSDN 订阅。我面临以下错误,

建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接)

谢谢,
乌梅什

请您参考如下方法:

由于您的本地数据库位于您的私有(private)本地网络中,Azure 服务找不到它,您可以为本地数据库公开一个公共(public) IP 或使用 Azure Web 应用服务 VNet integration与 Azure VPN gateway安全地访问 Azure VNet 或本地网络中的资源。

另一种推荐的方法是使用 Azure App Service Hybrid Connections .为此,您需要 add and create Hybrid Connections in your app .您将在数据库服务器或与本地数据库位于同一网络中的另一台服务器中下载并安装代理(混合连接管理器)。

主要步骤如下:

  1. You configure a logical connection on your app service or web app.
  2. A small agent, the Hybrid Connection Manager, is downloaded and installed on a Windows Server (2012 or later) running in the remote network (on-premises or anywhere) that you need to communicate with.
  3. You log into your Azure subscription in the Hybrid Connection manager and select the logical connection in your app service.
  4. The Hybrid Connection Manager will initiate a secure tunnel out (TCP 80/443) to your app service in Azure.
  5. Your app service can now communicate with TCP-based services, on Windows or Linux, in the remote network via the Hybrid Connection Manager.


您可以在 how to Connect Azure Web Apps To On-Premises 上获得更多详细信息.