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.

Zannith
  • 429
  • 4
  • 21
  • 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 – Srinath Ganesh Mar 10 '18 at 01: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"` – Zannith Mar 10 '18 at 01:31
  • Never seen that before, let me check – Srinath Ganesh Mar 10 '18 at 01:32
  • ah I think i found it [here](https://stackoverflow.com/questions/18620869/the-driver-could-not-establish-a-secure-connection-to-sql-server-by-using-secure) – Zannith Mar 10 '18 at 01:33
  • So I guess that means I won't be able to do my little hack on Android (unless I go the route they are suggesting) – Zannith Mar 10 '18 at 01:33
  • Yup ened up at the same link after a search... looking – Srinath Ganesh Mar 10 '18 at 01:33
  • Look at the comment in the 'accepted answer' that talks about the version... maybe that helps – Srinath Ganesh Mar 10 '18 at 01:35
  • Yea that's good to know. Well thank you for getting me one step closer to getting this done! Although almost obvious, If you want to post your initial comment as the answer I'll put it as accepted – Zannith Mar 10 '18 at 01:37
  • Also if you could mention that second error as being a problem doing this on android that would probably be helpful to people – Zannith Mar 10 '18 at 01:38
  • thats fine, nothing much to post in it. – Srinath Ganesh Mar 10 '18 at 01:38
  • Once you get it solved, you can answer your own question too. – Srinath Ganesh Mar 10 '18 at 01:38
  • Okay, I will do that if I ever get a finished solution. Thanks again – Zannith Mar 10 '18 at 01:39
  • lots of upvotes to this [answer](https://stackoverflow.com/a/19218578/1897935) but its a lot of work – Srinath Ganesh Mar 10 '18 at 01:52
  • 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 – Zannith Mar 10 '18 at 04:25
  • why do u need something more than SQlite? – Srinath Ganesh Mar 10 '18 at 04:27
  • Vision for the final product if to provide live updates on one device based off of changes made on another device so it is more than just keeping information on relevant to a single device. Was hoping to get a temporary easy fix to move forward in the project and set it up 'properly' later. – Zannith Mar 10 '18 at 17:04
  • never done such, maybe u got to send and receive JSON request and response via a web app – Srinath Ganesh Mar 10 '18 at 17:13

0 Answers0