Reputation: 1
I am struggling with how to connect Android app to SQL server 2008. Although when I try to connect to database server on a local machine from a simple Java project, it works fine, reads and fetches data.
But when I try this from Android application (jar file of JTDS is included in a library), it says: java.sql.SQLException: Network error IOException: failed to connect to 127.0.0.1:1433, connect failed: ECONNREFUSED (Connection refused) and many more errors. Also that it can't see database drive...
I am getting troubles with this: I set TCP ports to all IP addresses to 1433, enabled TCP/IP protocol, did everything that need to be done. But it is still not working. How I can solve this problem?? Any idea/suggestion would be appreciated.
Upvotes: 0
Views: 1423
Reputation: 3110
Local server Method
connect your system over the internet and generate the wifi from your computer.using IPCONFIG find your system IP.Then given the android app url based on your system ip like http://"SYS_IP":8080/YOUR_PATH
.
Connect your mobile internet using your system WIFI,Then it works fine.
Upvotes: 0
Reputation: 93559
You're trying to connect to 127.0.0.1. THis is the loopback address, it means you're trying to connect to the phone itself- which obviously doesn't have the database. That's your problem.
Also, connecting to the DB directly from the phone is a bad idea. It means your db is open to the internet. This is very insecure. Generally you put the db behind a firewall, and access it only via ssh-ing to a machine on the inside. Programs that need to access it from outside generally do so via a webservice, so that no computers outside the firewall have direct access to the db.
Upvotes: 1