0

I'm able to connect to local SQL server database by using Genymotion emulator. But when generate to APK and run on mobile, it doesn't connect to database. I notice the logcat shows "Connect failed: No route to host". I have turn on my wifi and the signal is very strong.

Below are methods that I have tried but still cannot solve it.

1) Turn ON/OFF wifi when run the app.

2) Set allow remote connection in SQL server.

3) Same network (Local IP= 192.168.0.110 Mobile IP: 192.168.0.114)

4) Using different port (80/1443)

My code:

con = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.110/app", "test", "1234");

or 

con = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.110:1443/app", "test", "1234");
ckcheah
  • 29
  • 8

1 Answers1

0

It is highly recommended not to connect to database servers from android directly. You need to have web server in between the android client and database server. Pass all your requests to the web server and make the web server in turn connect to the database.

Check this answer https://stackoverflow.com/a/12233178/3894784. It is for mysql database and almost similar to sqlserver with little changes in connection proerties.

Community
  • 1
  • 1
Harish Sridharan
  • 1,070
  • 6
  • 10
  • I know this is not a recommended way to connect database. But this app only use for testing purpose so I do not need to create web service first. The article I already read before but not very helpful for my case. But thank you for your answer. – ckcheah Jun 22 '15 at 05:35