0

I am attempting to connect to an Azure database via an android app I am creating, however I keep getting this particular error: Network error IOException: Could not create socket.

I can connect to the database on my login activity successfully, but if I reuse the same code on a different activity it will not connect at all.

I have attempted to reformat the connection string, but the problem persists. This is my current code to connect which is the same in the Login Activity:

String username = "username";
String password = "password";
String host = "jdbc:jtds:sqlserver://databaseUrl:1433/database"

try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        System.out.println("Connecting to database for duty...");
        Connection conn = DriverManager.getConnection(host, username, password);
        System.out.println("connected");
} catch (SQLException err) {
        System.err.println(err.getMessage());
} catch (Exception e) {
        System.err.println(e.getMessage());
}

Any help would be greatly appreciated

George C.
  • 31
  • 6
  • Connecting directly to a remote database from an Android app [is generally a **very** bad idea](https://stackoverflow.com/a/26471486/469080) – Michael Dodd Apr 05 '18 at 16:28
  • I do not know if it is possible to directly connect to a Databse Server from Android. See: https://stackoverflow.com/questions/3492417/connect-to-sql-server-from-android – julienduchow Apr 05 '18 at 16:30
  • http://msdn.microsoft.com/en-us/library/ms378428(v=sql.110).aspx host sould be in this format: jdbc:jtds:sqlserver://\SQLEXPRESS:1433;databaseName=database;user=username;password=password; But this is a bad idea to do. – sBanda Apr 05 '18 at 16:40

0 Answers0