I've been making several attempts but it has not worked.
My connection string is this:
public String conectar() throws ClassNotFoundException {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=prueba;integratedSecurity=true;";
conexion = DriverManager.getConnection(connectionUrl);
Sentencias = conexion.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
return "Conectado.";
} catch (SQLException ex) {
return "Error.\n"+ ex.toString();
}
}
I'm also doing this from a web service. This is the method to call it:
Conexion cnn = new Conexion();
String rs = "B";
try {
rs = cnn.conectar();
} catch (ClassNotFoundException ex) {
Logger.getLogger(ServicioWeb.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
But this error appears:
"Error. com.microsoft.sqlserver.jdbc.SQLServerException: No se pudo realizar la conexión TCP/IP al host localhost, puerto 1433. Error: "Connection refused: connect. Verifique las propiedades de conexión, compruebe que hay una instancia de SQL Server ejecutándose en el host y aceptando las conexiones TCP/IP en el puerto y compruebe que no hay ningún firewall bloqueando las conexiones TCP en el puerto."."
Use sql server 2014 express