Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired

Sanjeev Gupta 51 Reputation points
2021-09-15T07:09:20.237+00:00

Hi,

I have installed SQL Server 2019 on Linux platform and had done all the necessary steps and I was able to login to SQL Server via sqlcmd some time ago but suddenly I have started seeing below error when connecting to SQL Server via sqlcmd. i have verified for port as well and its open. please help me to fix this issue.

[rootanonymous user ~]# sqlcmd -Slocalhost -Usa -PXXXXX
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

[rootanonymous user ~]# firewall-cmd --list-ports
1433/tcp

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,724 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,436 Reputation points
    2021-09-16T06:36:26.063+00:00

    Hi @Sanjeev Gupta ,

    This is a generic error message when sqlcmd can't connect because the server is not online.
    Try to replace localhost with 127.0.0.1
    Please check the logs for more info. Troubleshooting info: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide?view=sql-server-ver15#access-the-log-files

    Best regards,
    Seeya


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    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 people found this answer helpful.

  2. Chavdar Rangelov 6 Reputation points
    2022-03-12T07:06:52+00:00

    Hi, I'm having the same problem with driver 18 and Ubunto 20.4, anyone had a solution to these issue?

    1 person found this answer helpful.

  3. Olaf Helper 40,816 Reputation points
    2021-09-15T08:15:16.853+00:00

    Then check first if the SQL Server is running at all, see Troubleshoot SQL Server on Linux

    0 comments No comments

  4. Seeya Xi-MSFT 16,436 Reputation points
    2021-09-20T01:52:39.163+00:00
    0 comments No comments

  5. Jajati Keshari Dev 0 Reputation points
    2023-09-07T15:34:09.03+00:00

    Hi

    I'm getting the following error message while executing the command in cmd. Please advice what could be the issue and how to fix it.

    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. .
    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

    0 comments No comments