• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Studio: Connecting to Local SQLExpress Server

Poak

Lurker
I am trying to connect to a local SQL server, but I'm getting exceptions. Code is below.

public class ConnectionClass {

String ip = "ipaddress\\servername";
String db = "databasename";
String un = "Username";
String password = "Password";

@SuppressLint("NewApi")
public Connection CONN() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
for (int tries = 0; tries < 3; tries++) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
ConnURL = "jdbc:sqlserver://" + ip + ";databaseName=" + db + ";user=" + un + ";password=" + password + ";";
conn = DriverManager.getConnection(ConnURL);
return conn;
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
}
return conn;
}
}

When I don't include the port number (1433) in the connection string. It says there is a TCP issue.

When I do, it times out and says to check if UDP traffic is blocked by firewall on port 1434 (it isn't) and to make sure SQL Browser is running (it is).

Any ideas?
 
Back
Top Bottom