简体   繁体   English

C#Web应用程序未通过Azure混合连接连接到本地SQL Server

[英]C# web app not connecting to on premise SQL Server through Azure hybrid Connection

Steps that I've taken so far 到目前为止我采取的步骤

  1. I've disabled the firewall and configured the SQL Server to allow remote connections 我已禁用防火墙并配置SQL Server以允许远程连接
  2. Verified if the hybrid connection manager has the connection established 验证混合连接管理器是否已建立连接
  3. Modified the connection string to specify the TCP ports 修改连接字符串以指定TCP端口

Please let me know if you have any further suggestions. 如果您有任何进一步的建议,请告诉我。

Thanks for the replies, I've finally figured it out.The mistake i was making was that i was specifying the SQL Server Name AND port number(433 in my case) ONLY while deplying to azure and in my code behind the connection string only had the server name mentioned. 感谢回复,我终于弄明白了。我犯的错误是我只是指定了SQL服务器名称和端口号(在我的情况下是433),同时只关注连接字符串后面的azure和我的代码有提到的服务器名称。

在此输入图像描述

However when I updated the connection string in my code behind to include the TCP port, i was able to successfully run the app in conjunction with the Hybrid connection to query results from the SQL Server. 但是当我更新后面代码中的连接字符串以包含TCP端口时,我能够成功运行应用程序与Hybrid连接一起查询来自SQL Server的结果。

在此输入图像描述

Recently I also worked on Azure hybrid connection and have made a list of all the possible problems that I faced. 最近我还参与了Azure混合连接,并列出了我遇到的所有可能出现的问题。 One of the following may be the cause: 以下之一可能是原因:

  • Hybrid Connection may only work with Default Instance of SQL Server and may fail in case of using a Named Instance. 混合连接可能仅适用于SQL Server的默认实例,并且在使用命名实例时可能会失败。 Even if the named instance is configured to use static TCP port yet might not work with the Hybrid Connection. 即使命名实例配置为使用静态TCP端口,但可能无法与混合连接一起使用。 The possible reason might be either your named instance might be listening on the same TCP port as your default instance. 可能的原因可能是您的命名实例可能正在侦听与默认实例相同的TCP端口。 As hybrid connection uses port for communication so in case when multiple instances are listening on the same port then hybrid connection might communicate to any of the one regardless of what instance you have supplied in your named instance. 由于混合连接使用端口进行通信,因此在多个实例正在侦听同一端口的情况下,无论您在命名实例中提供了什么实例,混合连接都可以与任何实例进行通信。
  • In order for hybrid connection to work you need to enable TLS 1.0 on your on premises machine for both server and client. 要使混合连接正常工作,您需要在本地计算机上为服务器和客户端启用TLS 1.0。 You need to add following registery value (if not already added): 您需要添加以下注册值(如果尚未添加):
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
  • The hybrid connection will only work if the connection string uses SQL Authentication ie, specifying the username and password in the connection string. 只有在连接字符串使用SQL身份验证时,即在连接字符串中指定用户名和密码,混合连接才有效。 Thus you can not use Windows Authentication. 因此,您无法使用Windows身份验证。
  • Although you do not need to open any firewall ports for inbound connectivity yet you are required to allow outbound connections to the following list of ports: 9350 – 9354, 5671, 80, 443 虽然您不需要为入站连接打开任何防火墙端口,但您需要允许出站连接到以下端口列表:9350 - 9354,5671,80,443
  • Azure hybrid connection requires Windows 8/Windows Server 2012 or later to work with. Azure混合连接需要Windows 8 / Windows Server 2012或更高版本才能使用。 The reason for this is that hybrid connection uses Web sockets that are not supported in the earlier windows version than these. 原因是混合连接使用早期Windows版本不支持的Web套接字。 Although you can use the classic hybrid connection (now depricated) to work with the earlier Windows. 虽然您可以使用经典的混合连接(现在已删除)来使用早期的Windows。
  • It is preferred to use the Fully-Qualified machine names for the endpoint and not the IP address. 最好使用端点的完全限定机器名称而不是IP地址。 In cases where the IP of your machine is unlikely to chnage there it might have no effect but in cases where the IP might change, you shuold use the machine name and let the HCM handle everything else for you. 如果您的机器的IP不太可能在那里进行,那么它可能没有任何效果,但是在IP可能发生变化的情况下,您需要使用机器名称并让HCM为您处理其他所有事情。

Also a very comprehensive walkthrough of creating a hybrid connection can be find here 同时形成混合连接的一个非常全面的演练,可以发现这里

Hope this solves your problem. 希望这能解决你的问题。

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

相关问题 Azure App服务无需内部连接即可在内部连接到SQL Server - Azure App service connect to SQL Server on premise without hybrid connection C#Web App与SQL Server的安全连接 - C# Web App secure connection to SQL Server Azure Web App 未使用连接字符串通过 VPN 连接到现场 SQL Server - Azure Web App is not connecting to On-Site SQL Server via VPN using connection string C#应用程序中的Sql Server连接错误 - Sql Server Connection Error in C# app 如何使用C#设置Azure中继混合连接以连接到本地SQL Server? - How to setup azure relay hybrid connections using C# to connect to on-premises SQL Server? 在 c# 中连接到 SQL '连接无效' 错误 - Connecting to SQL in c# 'Connection is invalid' error Azure 应用程序注册 - C# 应用程序的 SQL Server 权限 - Azure app registrations - SQL Server permission for C# App C#Web API使用Azure SQL Server数据 - C# Web API to consume Azure SQL Server Data 使用C#连接到服务器上的SQL Server数据库 - Connecting to SQL Server database on a server with C# 将已安装的C#应用​​程序连接到本地SQL Server 2005 Express-与可信SQL连接无关的用户 - Connecting installed C# application to local SQL Server 2005 Express - User not associated with trusted sql connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM