user3578325
user3578325

Reputation: 239

connection string for android to sqlserver

I've started developing an android application which connects to SQLServer DB, I've successfully connected to the DB with this connection string :

ConnURL = "jdbc:jtds:sqlserver://" + _IP+ ":" + _Port + ";" + "databaseName=" + _DB + ";useNTLMv2=true;integratedSecurity=true";

But it works only if i try it on a device which is connected to the same network in which the server is connected because the IP i put in the connection string is 192.168.1.7. What should i do to make it work if I try it in another network ? I've tried replacing that IP address with the IP address which i got from What Is My IP but it wont connect.

Upvotes: 1

Views: 1125

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93559

THat's because you're behind a NAT and that address isn't reachable to the outside world. You need to move to a server with a real IP address, or poke a hole in the NAT and allow address rerouting.

But that's ok, because you should NEVER directly connect to a db like this anyway- you not only have to allow your db server to be reached from a public internet, but you have to put your login info in your public app. Totally insecure. You should have a webservice between you and the db. The webservice should be the only one with the password, and it should get the data from the DB and return it in json or xml format.

Upvotes: 2

Related Questions