-3

Its working in AVD but same thing when i try do do in android device it give following error

java.sql.SQLException: Network error IOException: failed to connect to /192.168.0.226 (port 1433): connect failed: ETIMEDOUT (Connection timed out)
 java.sql.SQLException: Network error IOException: failed to connect to /192.168.0.226 (port 1433): connect failed: ETIMEDOUT (Connection timed out)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:372)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:181)
    at java.sql.DriverManager.getConnection(DriverManager.java:175)
    at java.sql.DriverManager.getConnection(DriverManager.java:209)
    at com.example.database1.MainActivity.query2(MainActivity.java:71)
    at com.example.database1.MainActivity$1.onClick(MainActivity.java:51)
    at android.view.View.performClick(View.java:4101)
    at android.view.View$PerformClick.run(View.java:17082)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4954)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.net.ConnectException: failed to connect to /192.168.0.226 (port 1433): connect failed: ETIMEDOUT (Connection timed out)
    at libcore.io.IoBridge.connect(IoBridge.java:114)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.Socket.startupSocket(Socket.java:565)
    at java.net.Socket.tryAllAddresses(Socket.java:127)
    at java.net.Socket.<init>(Socket.java:177)
    at java.net.Socket.<init>(Socket.java:149)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:252)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:297)
    ... 16 more
 Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
    at libcore.io.Posix.connect(Native Method)
    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
    at libcore.io.IoBridge.connect(IoBridge.java:112)
    ... 24 more
Maveňツ
  • 1
  • 12
  • 50
  • 89

1 Answers1

0

Maybe your real device cannot reach the host serving the database.

Make sure your android device is on the same subnet as your databse server (probably the same WiFi).

Also make sure the database does not listen only on localhost (127.0.0.1) but on all network interfaces (0.0.0.0). You only need to check this if the Android emulator runs on the same machine as the database server.

Last and least make sure no firewall is blocking the request.

Good luck!

Oderik
  • 2,242
  • 2
  • 16
  • 25
  • Thanks now its working on same network but when i connect to other net work in my android device it showing the same error – Mohammed Sameer Jan 07 '15 at 10:36
  • I'm not sure what you mean. Are you trying to reach your local area network database from outside that network? That would be a network configuration problem. As you are using a non public IP, I guess you are behind a NAT and / or firewall. You need to make sure that the NAT or firewall routes the request to your database host. The Android device must connect to your public address (of the router). But again, that's network configuration and a bit off the scope here I think. – Oderik Jan 08 '15 at 08:32
  • I mean to say that my Sql server data base on private network and if i want to perform CRUD function with my android app with mobile data or any other net work – Mohammed Sameer Jan 10 '15 at 08:47
  • Then my previous answer applies to your question. – Oderik Jan 12 '15 at 10:25