错误:与主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接 [英] Error:The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect

查看:75
本文介绍了错误:与主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

  • Windows 7
  • Netbeans IDE 7.1.2
  • SQL Server Management Studio Express 2005
  • JDK1.6

连接数据库时出现以下错误:

I am getting the below error while connecting to the database:

com.microsoft.sqlserver.jdbc.SQLServerException:到主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect

我的连接字符串是:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
Connection connection = DriverManager.getConnection(  
    "jdbc:sqlserver://127.0.0.1:1433;databaseName=dbcm;" +  
    "user=sa;password=sa");

我检查了以下内容:

  1. 在 SQL Server 配置管理器中,SQLEXPRESS 的协议:启用 TCP/IP事实上,我也启用了剩余的 3 个.
  2. SQL Server(SQLExpress) 和 SQL Browser 服务都在运行.

推荐答案

我按照以下步骤使用 JDBC 成功连接到 SQLExpress 实例:

I followed the steps below to successfully connect to an SQLExpress instance using JDBC:

  1. 使用 SQL Express 配置 TCP/IP 通信
  1. Configure TCP/IP communication with SQL Express
  1. 打开 SQL Server 配置管理器.
  2. 转到 SQL Server 网络配置 -> SQLEXPRESS 的协议
  3. 将 TCP/IP 协议的状态设置为已启用"(如果尚未启用).
  4. 打开 TCP/IP 的属性窗口,转到 IP 地址部分.
  5. 转到此属性页的底部,将IPAll 下的 TCP 端口设置为 1433.
  1. Open SQL Server Configuration Manager.
  2. Go to SQL Server Network Configuration -> Protocols for SQLEXPRESS
  3. Set the status of TCP/IP protocol to "Enabled" (if it is already not).
  4. Open Properties window for TCP/IP, go to IP Addresses section.
  5. Go to the bottom of this property page and set the TCP Port under IPAll to 1433.

  • 使用 Microsoft 的 SQL Server JDBC 驱动程序 连接到 SQLExpress 实例

  • Connect to the SQLExpress instance using Microsoft's JDBC driver for SQL Server

    1. JDBC URL:jdbc:sqlserver://localhost;instance=SQLEXPRESS;databaseName=;user=;password=

  • 这篇关于错误:与主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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