2

I am attempting to establish a connection to my local sqlserver instance on android with this line

Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:3306;DatabaseName=test", "admin", "password");

But I am getting this error

The TCP/IP connection to the host localhost, port 3306 has failed. Error: "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

I know that using jdbc to create direct database connections on android is not recommended for very good reasons, but that is not my concern right now.

I have verified in sql server configuration manager that tcp/ip is enabled for LOCAL and that IPAll TCP Port is set to 3306. I restarted the server after making these changes.

I have created a firewall rule allowing tcp/ip connections on port 3306 for local/domain connections inbound and outbound.

I checked the port with telnet telnet localhost 3306 and it connected.

Any help is appreciated, it is beginning to get frustrating.

17
  • your SQL Server is on your PC with ip X and your mobile has ip Y. localhost:3306 only works if both server and client have the same IP. if they are in different address, then you got to do something like 192.168.4.5:3306 in your JDBC connection Commented Mar 10, 2018 at 1:20
  • @SrinathGanesh Thank you! of course it was that simple. If its not too much to ask Perhaps you might understand this next error as well that just popped up The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Socket closed" Commented Mar 10, 2018 at 1:31
  • Never seen that before, let me check Commented Mar 10, 2018 at 1:32
  • ah I think i found it here Commented Mar 10, 2018 at 1:33
  • 1
    Ya, jTDS is a no go for sql server 2017, I think it started losing support at sql 2014 and I don't see anything about updates for 2017. It just won't pass the sql server authentication. just says login failed for user. Looks like I will have to go through the process of setting up a webserver and API's and everything Commented Mar 10, 2018 at 4:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.