现象:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
连接参数:
<property name="connection.username">sa</property> <property name="connection.url">jdbc:sqlserver://localhost\SqlExpress:1433;databaseName=gis9;</property> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="connection.password">123</property> <property name="connection.driver_class"> com.microsoft.sqlserver.jdbc.SQLServerDriver </property> |
错误提示:
com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
原因:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL Server数据库TCP/IP端口未正确设置。
解决:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
设置SQL Server数据库的ICP/IP协议端口为1433
- 打开SQL Server Configuration Manager
- 选择SQL Server 2005 Network Configuration->Protocols for SQLExpress
- 设置TCP/IP 为Enabled
- 双击TCP/IP项,选择IP Addresses页
- IP All中设置TCP Port为1433
- 重新启动服务