JDBC connection issue

Wylie, Robert 1 Reputation point
2021-08-03T13:33:07.743+00:00

I am trying to connect to my local sqlserver instance with the JDBC driver from the Visual Studio IDE. When I try to connect with the URL: "jdbc:sqlserver://localhost:1433;databaseName=master;user=sa;password=xxxx" , I get the error message: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host OCLPF2H20JA, port 1433 has failed. Error: "connect timed out. 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.". Since I am not going through any firewalls I am a bit lost as to what the issue is. Is there a SqlServer setting I am missing to allow that kind of traffic, or is this a JDBC issue of some kind?

SQL Server | Other
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2021-08-04T03:18:34.35+00:00

    Hi WylieRobert-4759,

    Welcome to Microsoft Q&A.

    Please go to check the following things:

    • Make sure the SQL Server instance is running.
    • Please go to SQL Server Configuration Manager -> expand SQL Server Network Configuration->Protocols for InstanceName, make sure TCP/IP is enabled.

    120307-image.png

    • Then go to TCP/IP properties-> IP Addresses tab, make sure SQL Server instance is listening on port 1433 under TCP port. 120264-image.png
    • Please make sure you have configured the firewall on the computer running SQL Server to allow access. Please refer to this doc which might help.

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Olaf Helper 47,441 Reputation points
    2021-08-04T05:21:11.03+00:00

    Can you connect to SQL Server using SSMS or SqlCmd with same parameter?
    Are you may using a SQL Server Express Edition as named instance? That one don't use port 1433 by default, but an other one.

    0 comments No comments

  3. Wylie, Robert 1 Reputation point
    2021-08-04T13:37:27.37+00:00

    I was able to get by the connection issue, but now I am getting the following error: An attempt to login using SQL authentication failed. Server is configured for Integrated authentication only". I have checked both servers and they are setup for both Windows and SQL.

    0 comments No comments

  4. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2021-08-05T01:51:20.43+00:00

    Hi WylieRobert-4759,
    Thanks for your reply.
    This error may be caused by SQL Server configured for Windows authentication only.
    You can use the follow query to check the SQL Server Authentication Mode:

    SELECT CASE SERVERPROPERTY('IsIntegratedSecurityOnly')     
    WHEN 1 THEN 'Windows Authentication'     
    WHEN 0 THEN ' SQL Server and Windows Authentication'     
    END as [Authentication Mode]    
    

    If the result is Windows Authentication, please go to SSMS, right-click the server, and then click Properties-> Security page, then select SQL Server and Windows Authentication instead.

    120615-image.png

    Best Regards,
    Amelia

    0 comments No comments

  5. Wylie, Robert 1 Reputation point
    2021-08-05T12:36:49.097+00:00

    Amelia,
    Thank you for the suggestion, but I have had the SQL Server and Windows Authentication Mode turned on and still get the same error.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.