1

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Is this your host 'MSSQL$SQLFULL'? More information is needed. Show the code and the DB setup. – Sully Jan 09 '16 at 11:28
  • @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 Jan 09 '16 at 11:30
  • 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 Jan 09 '16 at 11:34
  • @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 Jan 09 '16 at 11:41
  • I'm voting to close this question as off-topic because it is an exact duplicate of [this question](http://stackoverflow.com/q/34689149/2144390). – Gord Thompson Jan 09 '16 at 11:44
  • Possible duplicate of [SQL Server Connection Strings - dot(".") or "(local)" or "(localdb)"](http://stackoverflow.com/questions/20217518/sql-server-connection-strings-dot-or-local-or-localdb) – Sully Jan 09 '16 at 11:45
  • @HithamS.AlQadheeb do you think that there is a connection problem because of the name I give? But which is the correct one? Sorry if this is a stupid question but I am new to this and I really don't know what else can I do to fix this – Konstantina Papagiannopoulou Jan 09 '16 at 11:54

1 Answers1

5

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>"):
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
Sully
  • 14,672
  • 5
  • 54
  • 79
  • I was stumbling on this for more than a day and it did not strike me that there has to be two "\\" because one is an escape sequence. Thank you! – RGV Jun 27 '17 at 16:31
  • @RGV, glad this answer helped – Sully Jun 28 '17 at 03:42