title: JDBC connection failed, error: TCP/IP connection to host failed
body: <p>I want to connect Java class file with SQL server 2012. I have logged in with SQL server authentication, but I am receiving an error when connecting.</p>
  <p>Error:</p>
  <blockquote>
  <p>The TCP/IP connection to the host 127.0.0.1, port 1433 has failed.
  Error: &quot;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.&quot;.</p>
  </blockquote>
  <p>My code:</p>
  <pre><code>Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);  //1. Register your driver
  //2. get the connection object
  //Connection con = DriverManager.getConnection(&quot;jdbc:sqlserver://localhost;databaseName=aysha&quot;,&quot;sa&quot;,&quot;admin&quot;);
  Connection con = DriverManager.getConnection(&quot;jdbc:sqlserver://127.0.0.1;databaseName=aysha&quot;,&quot;user=sa&quot;,&quot;password=admin&quot;);
   //&quot;jdbc:sqlserver://127.0.0.1:1433; Instance=SQL2008;&quot; +       &quot;databaseName=MB;user=sa;password=123;&quot;;
  //Connection con = DriverManager.getConnection(&quot;jdbc:sqlserver://localhost:1433;databaseName=aysha&quot;,&quot;sa&quot; , &quot;password&quot;);
  //3. Prepare a statement
  Statement stmt = con.createStatement();
  //4. Write the query`
  String sql = &quot;Select * from employee&quot;;
  //5. Execute the statement and 
  ResultSet rs = stmt.executeQuery(sql);
  //6. Process the result set
  
  while (rs.next())
  {
      System.out.println(rs.getInt(1));
  }
  </code></pre>