无法在Mac中打开Azure SQL数据库的端口1433 [英] Cannot open port 1433 for Azure SQL database in Mac

查看:136
本文介绍了无法在Mac中打开Azure SQL数据库的端口1433的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问Java应用程序上由Azure托管的SQL数据库.我使用nmap检查了端口1433,它显示它已关闭:

I'm trying to access a Azure-hosted SQL database on my java application. I checked the port 1433 using nmap and it shows that it's closed:

Starting Nmap 7.12 ( https://nmap.org ) at 2016-09-02 09:44 PHT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Other addresses for localhost (not scanned): ::1
PORT     STATE  SERVICE
1433/tcp closed ms-sql-s

我已经编辑了/etc/pf.conf并重新启动了Mac,但是该端口仍然关闭.这是我的pf.conf:

I have edited the /etc/pf.conf and restarted my mac but the port is still closed. Here is my pf.conf:

scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
pass in proto tcp from any to any port 1433

此外,我的防火墙设置为关闭.

Also, my firewall is set to off.

我的Java应用抛出此错误:

My java app is throwing this error:

Error starting database: The TCP/IP connection to the host flowengine7.database.windows.net, port 1433 has failed. Error: "Connection timed out: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

Java代码:

 String connectionString =
                "jdbc:sqlserver://dbName.database.windows.net:1433;database=dbName;user=user@@user;password=passwordhere;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

        Connection connection = null;

        try {
            connection = DriverManager.getConnection(connectionString);
            println 'connected';
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            if (connection != null) try {
                connection.close();
            } catch (Exception e) {
            }
        }

推荐答案

您正在忽略Azure SQL 服务器级防火墙:
https://azure.microsoft.com/en-us/documentation/articles/sql-database-configure-firewall-settings/

You're overlooking the Azure SQL server-level Firewall:
https://azure.microsoft.com/en-us/documentation/articles/sql-database-configure-firewall-settings/

您需要在其中列出Mac的公共IP地址,以便能够从本地连接.默认情况下,只有Azure服务可以在您的Azure SQL实例上达到1433/TCP(由允许访问Azure SQL防火墙中的Azure服务设置允许).

You need to whilelist your Mac's Public IP address in there to be able to connect from local. By default only Azure services can reach 1433/TCP on your Azure SQL instance (permitted by Allow access to Azure Services setting in the Azure SQL Firewall).

如果每次重新启动DSL/Cable/Fiber调制解调器时都获得一个新的公共IP地址,则需要定义整个地址范围,而不仅仅是一个(即 174.73.0.0-174.73.). 255.255 与列表 174.73.16.180 ).希望您将始终获得相同范围内的IP地址.

If you're getting a new Public IP address every time you reboot your DSL/Cable/Fiber modem you'll need to define a whole range of addresses not just the one (i.e. 174.73.0.0 - 174.73.255.255 vs. listing 174.73.16.180). Hopefully you'll always grab an IP address in the same range.

这篇关于无法在Mac中打开Azure SQL数据库的端口1433的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆