I know that this is a repeated question. I have found very similar questions and solutions to them but still i'm struck with it.
I'm using eclipse to connect my java application with microsoft sql server 2008 database. Following is my code
import java.sql.*;
public class ConnectionTest2 {
public static void main(String [] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=Sample;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl,"","");
System.out.println("Connected");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
}
}
I've enabled the tcp/ip and VIA by going in to sql server configuration manager and set the port number to 1433 under IPALL.
I've tried in many ways but i'm unable to find a solution to the following error
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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.".
I've also disabled the windows firewall but failed to connect.
Please help me out.
Try the command telnet localhost 1433 in cmd to make sur - Udi Cohen 2012-04-05 20:14
It is what it says: connection is refused. Have you tried 'telnet 1433'?
I had this problem and I fixed it by enabling the TCP/IP protocol for the server instance. You can do that by
After this, You need to restart the SQL Server service to make it effective.