user3215134
user3215134

Reputation: 51

Android Application Network Error failed to connect

I'm using the following coding to connect locally on my SQL database

String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://127.0.0.1:1433/dbname";
conn = DriverManager.getConnection(connString,"user","pass");

When I'm running this application it gives me Network error. Failed to connect to 127.0...

My firewall is open for 1433 and SQL config TCP/IP is enabled. What else must I still do?

Upvotes: 2

Views: 7024

Answers (2)

user3215134
user3215134

Reputation: 51

I fix this error. I was working on jtds driver v1.3.1. When I'm using the older version it works. I'm using now v1.2.5

Upvotes: 0

Chirag Ghori
Chirag Ghori

Reputation: 4231

If you are referring to a localhost from your device than use the http://10.0.2.2:8080/ instead of the http://127.0.0.1/ or http://localhost/.

Because your Android emulator is running on a Virtual Machine(QEMU) and you can not connect to a server directly running on your PC.

And If you running your app from Physical android device then please use your network ip from your PC. for example http://198.10.12.21:80/....

Also make sure that your device and PC(from where you call localhost) within same Network

Upvotes: 6

Related Questions