Sqlcmd command fails in azure pipeline

Kanagamanikandan Duraisamy 25 Reputation points
2024-04-06T09:30:27.44+00:00
az account get-access-token --resource https://database.windows.net --output tsv | cut -f 1 | tr -d '\n' | iconv -f ascii -t UTF-16LE > /tmp/tokenFile

sqlcmd -S xxx.net,1433 -d yyy -G -P /tmp/tokenFile -Q "SELECT GETDATE()"

I have the above script in our pipeline and it was running successful so far. But suddenly it has started to fail and I could not find a way to fix it.

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 0x2AF9.

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.

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

Accepted answer
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2024-04-10T04:40:13.4866667+00:00

    Hi Kanagamanikandan Duraisamy,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Solution: The issue is resolved after removing the quotes surrounding the server name.

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    Thanks

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Achraf Ben Alaya 1,311 Reputation points MVP
    2024-04-06T12:17:43.9333333+00:00

    Hi ,

    The infomrations that you have provided indicate that there is a network issue ,server configuration or firewall issues .

    1- check if the vm from the pipline can reach the server first
    2-verify sql server name and port
    3-check if there was a change in configuration of the server : allow remote connection
    4-check if the port 1433 allowed in firewall
    5-Check the validity of the used token
    6-Check Sql server logs for more informations .

    Also please Check :

    https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/directaccess-clients-not-connect-to-server?wt.mc_id=MVP_328341

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

  2. Kanagamanikandan Duraisamy 25 Reputation points
    2024-04-08T12:33:30.68+00:00

    The issue is resolved after removing the quotes surrounding the server name.

    0 comments No comments

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.