0

I've just recently installed MS SQL Server 2017 on my machine, and I'm facing this issue where just opening the connection is taking too long.

this line alone takes 5.5 seconds: con = DriverManager.getConnection(connectionUrl)

package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Test
{
    static
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
        }
        catch (Exception e)
        {
        }
    }
    public static void main(String[] args) throws SQLException
    {

        Connection con = null;

        try
        {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=BSSGI;user=bssuser;password=123456";
            long startTime, endTime, total;
            startTime = System.currentTimeMillis();
            con = DriverManager.getConnection(connectionUrl);
            endTime = System.currentTimeMillis();
            total = endTime - startTime;
            System.out.println("Con:" + total);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.exit(0);
        }
        finally 
        {
            con.close ();
        }
    }

}

And this is the output that I'm getting:

run:
Con:5582
BUILD SUCCESSFUL (total time: 5 seconds)

I am able to connect to the server through MS SQL Management Studio fine and I dont see any issue with query speed or connectivity. The server is currently run on a powerful machine, and an nvme SSD (Samsung 970 pro); so I doubt it's a machine's performance issue. And the test program and the server are on the same machine, so I doubt it's got anything to do with network.

Thank you in advance.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418

0 Answers0