I am tring to connect sql server from android device in local network. getting below error while connection. I am using PC host name instead of ip address due to ip change issues. I have also check firewall is off. can u plz help me in this matter.?
Thanks in advance..
ERROR:
The TCP/IP connection to the host DESKTOP-VPJ3BFC, port 1433 has failed. Error: “Unable to resolve host “DESKTOP-VPJ3BFC”: No address associated with hostname. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.”.
Library Used: implementation ‘com.microsoft.sqlserver:mssql-jdbc:9.4.0.jre8’
Code:
public Connection connectionclasss(String user, String password, String database, String server, String instance)
{
////Log.d(“In conn”,”In connection s”);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = “”;
//DESKTOP-VPJ3BFC
server=”DESKTOP-VPJ3BFC:1433″;
try
{
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
ConnectionURL = “jdbc:sqlserver://” + server + “;”+ “databaseName=” + database;
connection = DriverManager.getConnection(ConnectionURL,user,password);
}
catch (SQLException se)
{
Log.e(“error here 1 : “, se.getMessage());
analyzeSQLException(se);
}
catch (ClassNotFoundException e)
{
Log.e(“error here 2 : “, e.getMessage());
}
catch (Exception e)
{
Log.e(“error here 3 : “, e.getMessage());
}
return connection;
}
I have connected successfull with ip address
suhas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.