0
votes

I am new to JDBC connections and I am very confused. I have enable TCP/IP and Named Pipes and in TCP/IP -> IP Adresses I have set TCP port to 1433 and I have restarted the server. I have also open access to SQL Server via Windows Firewall with Advanced Security. The problem is that I still get this error:

SQLException: The TCP/IP connection to the host MSSQL$SQLFULL, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."

I run on cmd the following: telnet SQLFULL 1433 and I get this message: Could not open connection to the host on port 1433 : connect failed

My code:

String url = "jdbc:sqlserver://MSSQL$SQLFULL:1433;databaseName=BA_ELTRUN;";
Connection dbcon = null;
String errorMessages = "";

try
{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(java.lang.ClassNotFoundException e)
{
    System.out.print("ClassNotFoundException: ");
    System.out.println(e.getMessage());
}

try
{
    dbcon = DriverManager.getConnection(url,"username","password");
}
catch(SQLException e)
{
     System.out.print("SQLException: ");
     System.out.println(e.getMessage());
     errorMessages = "Could not close connection with the Database Server: <br>"
                    + e.getMessage();
                    throw new SQLException(errorMessages);
}

Can anyone help?

1
Is this your host 'MSSQL$SQLFULL'? More information is needed. Show the code and the DB setup.Sully
@HithamS.AlQadheeb I add my code. MSSQL$SQLFULL is in "log on as" field in SQL Server Configuration Management. In field Name it is: SQL Server (SQLFULL)Konstantina Papagiannopoulou
Change that value to the 'Server Name' of the login of the MS SQL Server Management. Also, the error message should indicate that a connection could not be opened instead of could not close.Sully
@HithamS.AlQadheeb It is .\SQLFULL but this "\" is not accepted from compiler. I get the message "illegal escape character". I tried "SQLFULL" but I still get this message "SQLException: The TCP/IP connection to the host SQLFULL, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."."Konstantina Papagiannopoulou
I'm voting to close this question as off-topic because it is an exact duplicate of this question.Gord Thompson

1 Answers

5
votes

Copy computer name :cmd.exe -> hostname

or

Right Click on Start then click on System and copy the Computer Name

URL should be:

String url = "jdbc:sqlserver://<Computer Name>\\SQLFULL:1433;databaseName=BA_ELTRUN;";

Connection conn = DriverManager.getConnection(url,"<user>","<password>"):