SQLException: The TCP/IP connection to the host lo

2019-09-14 04:02发布

问题:

This question already has an answer here:

  • SQL Server Connection Strings - dot(“.”) or “(local)” or “(localdb)” 1 answer
  • The TCP/IP connection to the host, port 1433 has failed 1 answer

when I run a JDBC connection I get the following exception: "SQLException: The TCP/IP connection to the host localhost, port 1433 has failed."

I read many answers to similar questions, I have enabled named pipes and TCP/IP and I have set port number in IPAII to 1433. However, I still get this message. Please help!!

My code:

    String url = "jdbc:sqlserver://SQLFULL:1433;databaseName=BA_ELTRUN;";
    Connection dbcon = null;

    try
    {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    }
    catch(java.lang.ClassNotFoundException e)
    {
        System.out.print("ClassNotFoundException: ");
        System.out.println(e.getMessage());
    }

    try
    {
        dbcon = DriverManager.getConnection(url,"username","password");
    }
     catch (Exception e)
     {
        errorMessages = "Could not close connection with the Database Server: <br>"
                        + e.getMessage();
                        throw new SQLException(errorMessages);
    }