title: SQLServerException connection refused
body: <p>First of all I know this question is asked many times -In different ways- in here but in my case this is not a duplicate because I have a different case that I already have done all the answers and nothing worked.</p>
  
  <p>My problem is I am trying to connect to sqlserver database (NOT Sql express) and whenever I try to I get this error</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "localhost/127.0.0.1:1433 - Connection refused. 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.".
  </code></pre>
  
  <p>Notes:</p>
  
  <p>1- I enables my firewall to accept connections to port 1433 and I am able to connect to my database from my windows forms application and my java application but not from android application.</p>
  
  <p>2- I enables TCP/IP connections to my sql server from the sql server configuration manager.</p>
  
  <p>3- The port for TCP/IP connections is 1433.</p>
  
  <p>4- The same connection string with the same jdbc driver works with java application.</p>
  
  <p>5- My database is in the same development computer.</p>
  
  <p>6- I am using sqlserver database not sqlexpress (I know I mentioned this before just to make sure people notice :) )</p>
  
  <p>7- My code looks like this:</p>
  
  <pre><code>try {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          con=DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=dbname", "user", "password");
          Statement s=con.createStatement();
          ResultSet rs=s.executeQuery("SELECT * FROM Table WHERE ID=0");
  
  
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>
  
  <p>8- I tried to add instance name to my connection string but still didn't work.</p>
  
  <p>Thank you in advance guys and if someone had the same problem before and worked it around please help.</p>