【问题标题】:Connecting to external database through telnet通过 telnet 连接到外部数据库
【发布时间】:2011-10-24 06:23:19
【问题描述】:

我有一个连接到 MS SQL 数据库的 java 程序。该程序在通过 Eclipse 运行时完美运行,但是当我通过 AIX 运行它时出现错误:

java.sql.SQLException:网络错误 IOException:远程主机拒绝了尝试的连接操作。

我可以成功地 ping 服务器,但无法 telnet 进入服务器。我也无法从我的 Windows 桌面远程登录。

我正在使用jtds连接:

String connectionString = "jdbc:jtds:sqlserver://"+dropez_ip_address+"/"+dropez_db_name;
ResultSet rs = null;
Statement stmt = null;

try{

    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection conn = DriverManager.getConnection(connectionString, dropez_db_username, dropez_db_password);

    stmt = conn.createStatement();
}catch(Exception e){}

这里有一些来自 jTDS 的关于该问题的文档,但我仍然无法解决该问题。

Why do I get java.sql.SQLException: "Network error IOException: Connection refused: connect" when trying to get a connection?

The "Connection refused" exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:

    - The server name is misspelled or the port number is incorrect.
    - SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
    - There is a firewall blocking port 1433 on the server.

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.

【问题讨论】:

  • “我可以成功 ping 服务器,但无法远程登录服务器。我也无法从我的 windows 桌面远程登录。”你的意思是远程登录不是已安装,或者您没有使用它的权限,或者您尝试在那里 telnet 并且没有(或某些事情)发生?
  • Telnet 与此无关。您没有通过 telnet 连接到数据库。您的数据库服务器不允许从您的应用程序连接到 SQL Server 端口 (1433);这可能是网络配置或防火墙配置问题,而不是软件问题。

标签: java unix telnet jtds


【解决方案1】:

如果您无法在端口 1433 上进行 telnet,则您的计算机和服务器之间的某处被防火墙阻止了。这不是 java 相关的问题。

可能是当您说“它在 Eclipse 下完美运行,但在 AIX 下不能完美运行”时,您正在使用大约 2 台不同的计算机?如果是这样,带有 eclipse 的那个没有防火墙,您部署应用程序的那个被阻止。

但同样,与 java 无关。这是 TCP-IP 模型的三级错误(TCP 层)。

问候, 斯蒂芬

【讨论】:

  • 是的,程序在我的桌面上运行时运行,但在我从 AIX 服务器运行时不运行。
  • 那么,很可能是 AIX 服务器上的防火墙阻止了 telnet 端口上的传出连接,或者网络上其他地方的规则。
【解决方案2】:

您的 SQL Server 数据库可能没有启用 TCP/IP 协议来启用它:

  1. 从 Microsoft SQL Server 2005 -> 配置工具,打开“Microsoft SQL Server 配置管理器”。

  2. 展开“SQL Server 2005 网络配置”,然后单击“协议”。

  3. 右键单击“TCP/IP”,然后单击“启用”。该协议的图标将更改以显示该协议已启用。

对于 SQL Server 2008:

【讨论】:

  • 我使用的是 SQL Server 2008,当我打开 SQL Server 配置管理器时,我发现数据库位于“SQL Native Client 10.0 配置 -> 别名”下,协议是“tcp”,我不是有幸改变它。
  • @Mike 我添加了一个屏幕截图,用于在 SQL Server 2008 中检查它。
  • 我没有这些选项,可能是因为数据库不是我的,而是由托管服务提供的?
  • @Mike 如果您的数据库在托管服务中,并且您的桌面连接到远程托管服务,那么肯定与 AIX 防火墙配置有关,您需要启用 1433 端口出站流量。托管服务是否允许来自任何 IP 的连接,还是必须允许某些 IPS?也检查一下。
  • 托管服务说也是防火墙,我再看看,谢谢你的帮助!
猜你喜欢
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
  • 2017-05-23
  • 2021-02-26
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
相关资源
最近更新 更多