简体   繁体   English

如何修复:com.microsoft.sqlserver.jdbc.SQLServerException?

[英]How to fix it: com.microsoft.sqlserver.jdbc.SQLServerException?

I want to connect to sql server express. 我想连接到SQL Server Express。 I downloaded this driver. 我下载了驱动程序。 I read the help file and this is my code: 我阅读了帮助文件,这是我的代码:

        try 
        {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://localhost;database=ActorsDb;integratedSecurity=true;";
            Connection con = DriverManager.getConnection(connectionUrl);
            PreparedStatement st = con.prepareStatement("INSERT INTO Actors(FirstName,LastName,Age) VALUES(?,?,?)");
            st.setString(1, "Robert");
            st.setString(2, "de Niro");
            st.setInt(3,45);
            st.executeUpdate();     
            con.close();
        } 
        catch (SQLException | ClassNotFoundException e) 
        {
            e.printStackTrace();
        }   

I get this exception: 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.". 我收到此异常: 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.". 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.".

I turned off firewall but nothing changed. 我关闭了防火墙,但没有任何改变。

  1. I went to SQL Server Configuration Manager and i enabled TCP/IP 我去了SQL Server配置管理器并启用了TCP / IP

  2. I went to IP Adresses, IP1 and set the properties 我去了IP地址IP1并设置了属性

Active:Yes ; 活动:是; Enabled:Yes ; 启用:是; TCP Dynamic Ports:[empty] ; TCP动态端口:[空]; TCP Port:1433 TCP端口:1433

Any tips of what i am missing? 我所缺少的任何提示吗? Thanks. 谢谢。

Check if the SQL Server service is running and check if any programs like anti-virus is blocking the connections. 检查SQL Server服务是否正在运行,并检查是否有诸如防病毒程序之类的程序阻止了连接。 If so, disable them or add exception to that connection. 如果是这样,请禁用它们或向该连接添加例外。

You're using localhost in your JDBC URL, try instead using the IP address for "IP1" that you describe in SSCM. 您在JDBC URL中使用本地主机,请尝试使用在SSCM中描述的“ IP1”的IP地址。 Or, verify SSCM is configured to listen on localhost:1433. 或者,确认SSCM已配置为在localhost:1433上侦听。

Problem solved. 问题解决了。 I had to copy sqljdbc_auth.dll in the working directory. 我必须在工作目录中复制sqljdbc_auth.dll。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.microsoft.sqlserver.jdbc.SQLServerException 与 jpa - com.microsoft.sqlserver.jdbc.SQLServerException with jpa com.microsoft.sqlserver.jdbc.SQLServerexception:'='附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerexception:incorrect syntax near'=' com.microsoft.sqlserver.jdbc.SQLServerException:用户登录失败 - com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 无法创建交易异常:com.microsoft.sqlserver.jdbc.SQLServerException 登录错误 - CannotCreateTransactionException: com.microsoft.sqlserver.jdbc.SQLServerException Login Error com.microsoft.sqlserver.jdbc.SQLServerException:'GO'附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'GO' com.microsoft.sqlserver.jdbc.SQLServerException: ')' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ')' com.microsoft.sqlserver.jdbc.SQLServerException: 索引 2 超出范围:( - com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range :( com.microsoft.sqlserver.jdbc.SQLServerException:无效的列名称“ xxx” - com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'xxx' com.microsoft.sqlserver.jdbc.sqlserverexception:参数编号1无效 - com.microsoft.sqlserver.jdbc.sqlserverexception: the parameter number 1 is not valid com.microsoft.sqlserver.jdbc.SQLServerException: '=' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '='
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM