• java连接sqlserver报错


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

    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数据库了。

               

  • 相关阅读:
    统计学习方法 | 第1章 统计学习方法概论
    统计学习方法 | 第2章 感知机
    LeetCode | DP专题详解
    论文阅读 | Towards a Robust Deep Neural Network in Text Domain A Survey
    DFS(深度优先搜索)和BFS(广度优先搜索)
    Analysis Methods in Neural Language Processing: A Survey
    Spring AMQP 发送消息到 RabbitMQ 收到 x-queue-type 错误
    Gradle 的项目导入到 IntelliJ 后子项目源代码不能导入
    在 CentOS 7 上安装 RabbitMQ
    IntelliJ IDEA 运行项目的时候提示 Command line is too long 错误
  • 原文地址:https://www.cnblogs.com/CKhomepage/p/10963408.html
Copyright © 2020-2023  润新知