当前位置:   article > 正文

java 连接sqlserver_java连接sqlserver报错

verify the connection properties. make sure that an instance of sql server i

使用Java进行项目开发,一般是使用MySQL数据库,由于项目需要本次换成了SQLServer数据库,在eclipse中进行连接测试时驱动类、URL地址、用户名和密码都正确,但是会抛出以下异常,无法正确连接到SQLServer数据库

7320b078089c072ff3c829e0675d961f.png

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed.

Error: "Connection refused: connect. 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.".

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:206) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:257) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2385) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:567) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1955) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1616) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1447) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:788) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1187) ~[mssql-jdbc-6.1.0.jre8.jar:na]

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1408) ~[druid-1.0.18.jar:1.0.18]

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1464) ~[druid-1.0.18.jar:1.0.18]

at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1969) ~[druid-1.0.18.jar:1.0.18]

————————————————————————————————————

这是由于SQLServer安装默认是禁用TCP/IP协议的,而连接SQLServer需要启用TCP/IP协议

解决方法:在搜索栏中搜索SQLServer,打开SQLServer配置管理器,在SQLServer配置器的网络配置中启用TCP/IP协议。

修改之后就可以成功连接到SQLServer数据库了。

bb2a62ad44d2b43d9346d5e55525fd18.png           

7187e654fb41ba4856c2bde4d560d067.png

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号