Question

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.

My problem is I am trying to connect to sqlserver database (NOT Sql express) and whenever I try to I get this error

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.".

Notes:

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.

2- I enables TCP/IP connections to my sql server from the sql server configuration manager.

3- The port for TCP/IP connections is 1433.

4- The same connection string with the same jdbc driver works with java application.

5- My database is in the same development computer.

6- I am using sqlserver database not sqlexpress (I know I mentioned this before just to make sure people notice :) )

7- My code looks like this:

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();
    }

8- I tried to add instance name to my connection string but still didn't work.

Thank you in advance guys and if someone had the same problem before and worked it around please help.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top