简体   繁体   English

Azure SQL 虚拟机中的托管实例连接

[英]Azure SQL Managed Instance Connection in Virtual Machine

We have setup where our applications are hosted in Azure Virtual Machine, and our Databases are hosted in SQL Managed instance.我们已经设置了我们的应用程序托管在 Azure 虚拟机中,我们的数据库托管在 SQL 托管实例中。 Both are in same region, same subscriptions, but different Vnet as is the requirement of SQL Managed Instance.两者都在同一个区域,相同的订阅,但不同的 Vnet 是 SQL 托管实例的要求。

We have whitelisted the IPs, open the port on NSG of both VM and SQL Instance.我们已将 IP 列入白名单,在 VM 和 SQL 实例的 NSG 上打开端口。

We are able to open SQL in SSMS, in the local machine as well as in the VM itself.我们能够在 SSMS、本地机器以及 VM 本身中打开 SQL。 But for some reason same server does not work when added in the connection string.但是由于某种原因,同一服务器在添加到连接字符串中时不起作用。

We have tried with both 1433 and 3342 ports.我们已经尝试了 1433 和 3342 端口。 We have tried proxy vs redirect We have tried VNET Peering as well, But nothing seems to work, we always get below error:我们尝试过代理与重定向我们也尝试过 VNET Peering,但似乎没有任何效果,我们总是收到以下错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server.与 SQL 服务器建立连接时发生与网络相关或特定于实例的错误。 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.验证实例名称是否正确,并且 SQL 服务器配置为允许远程连接。 (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)' (提供者:TCP 提供者,错误:0 - 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应。)'

Our applications are based on.Net.我们的应用程序基于.Net。

We are moving our servers from on-premise to Azure.我们正在将我们的服务器从本地迁移到 Azure。

Any help will be appreicated.任何帮助将不胜感激。

Thank you.谢谢你。

As both Virtual Machine and SQL managed instance are in different VNETs, we need to do VNET peering to allow the applications in the Virtual Machine to connect to SQL Server.由于虚拟机和 SQL 托管实例位于不同的 VNET 中,因此我们需要进行 VNET 对等以允许虚拟机中的应用程序连接到 SQL 服务器。

Now, we need to write NSG rules to allow Virtual Machine to connect to the SQL server through 1433, 3342 and 4022 ports.现在,我们需要编写 NSG 规则以允许虚拟机通过 1433、3342 和 4022 端口连接到 SQL 服务器。

Then your application in the virtual machine will be able to connect to the SQL server然后你在虚拟机中的应用就可以连接到SQL服务器了

To access the SQL server through public link, we have to whitelist the IP address of the virtual machine.要通过公共链接访问 SQL 服务器,我们必须将虚拟机的 IP 地址列入白名单。

To access the SQL server through private endpoint, we need to host the private endpoint in the same VNET of the SQL server.要通过私有端点访问 SQL 服务器,我们需要将私有端点托管在 SQL 服务器的同一 VNET 中。 Then through VNET peering, the application in the VM can access the SQL server.然后通过 VNET 对等互连,VM 中的应用程序可以访问 SQL 服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM