错误:与主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接 [英] Error:The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect
本文介绍了错误:与主机的 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");
我检查了以下内容:
- 在 SQL Server 配置管理器中,SQLEXPRESS 的协议:启用 TCP/IP事实上,我也启用了剩余的 3 个.
- SQL Server(SQLExpress) 和 SQL Browser 服务都在运行.
推荐答案
我按照以下步骤使用 JDBC 成功连接到 SQLExpress 实例:
I followed the steps below to successfully connect to an SQLExpress instance using JDBC:
- 使用 SQL Express 配置 TCP/IP 通信
- Configure TCP/IP communication with SQL Express
- 打开 SQL Server 配置管理器.
- 转到 SQL Server 网络配置 -> SQLEXPRESS 的协议
- 将 TCP/IP 协议的状态设置为已启用"(如果尚未启用).
- 打开 TCP/IP 的属性窗口,转到 IP 地址部分.
- 转到此属性页的底部,将
IPAll
下的 TCP 端口设置为 1433.
- Open SQL Server Configuration Manager.
- Go to SQL Server Network Configuration -> Protocols for SQLEXPRESS
- Set the status of TCP/IP protocol to "Enabled" (if it is already not).
- Open Properties window for TCP/IP, go to IP Addresses section.
- Go to the bottom of this property page and set the TCP Port under
IPAll
to 1433.
Microsoft 的 SQL Server JDBC 驱动程序
连接到 SQLExpress 实例
Microsoft's JDBC driver for SQL Server
- JDBC URL:
jdbc:sqlserver://localhost;instance=SQLEXPRESS;databaseName=
莉>;user= ;password=
这篇关于错误:与主机的 TCP/IP 连接失败.java.net.ConnectException:连接被拒绝:连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文