title: The TCP/IP connection to the host localhost, port 1433 has failed error, need assistance
body: <p>Full error I'm getting:</p>
  
  <p>The TCP/IP connection to the host localhost, port 1433 has failed. Error: "connect timed out. 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.".</p>
  
  <p>I have already checked that TCP/IP is enabled, using port 1433, and TCP dynamic ports is empty. I have disabled windows firewall. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.sql.*;
  
  public class DBConnect {
  
  
  
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
  
      String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=TestDB1;instance=SQLSERVER;encrypt=true;TrustServerCertificate=true;";
      String user = "sa";
      String pass = "";
      try {
      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  
  
      Connection myConn = DriverManager.getConnection(dbURL, user, pass);
      try {
      Statement myStmt = myConn.createStatement();
  
      try {
      ResultSet myRs = myStmt.executeQuery("Select * from Login");
  
  
  
          while (myRs.next())
          {
              System.out.println(myRs.getString("Username"));
              System.out.println(myRs.getString("Password"));
          }
      }
      catch (Exception e)
      {
          System.out.println("Error with query");
      }
      }
  
      catch (Exception e)
      {
          System.out.println("Error connecting to database");
      }
      }
  
      catch (Exception e)
      {
          System.out.println(e);
      }
  }
  </code></pre>
  
  <p>}</p>