How to connect and query Azure SQL Database from CLI in windows 11

Navarathina Raja, Arun Kumar 0 Reputation points
2023-07-24T16:42:17.4333333+00:00

I have 2 Database instances under a particular Resource group, which are password protected. I need to connect Azure SQL Database from CLI in windows machine and run a query to validate the tables in the database.

Using the commands az login and az account set --subscription I am able to get the azure account details and using the command

az sql db show --name <database-name> --resource-group <resource-group-name> --server <server-name> --output json

I am able to get the Database details.

But after this step I am not able to use any of the commands to give username and password to enter into the db and quering.

Could someone provide me the command to provide credentials and enter the db and validate the db data?

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Oury Ba-MSFT 20,911 Reputation points Microsoft Employee Moderator
    2023-07-24T23:50:39.2933333+00:00

    Navarathina Raja, Arun Kumar

    Thank you for being patient while working on this.

    I was able to test it first using the Cloud Shell PowerShell. I was able to successfully connect and create new table.

    User's image

    Then I tried using CLI

    using the same command below

    sqlcmd -S servername -d databasename -U username - P password

    Note that you will need to replace <servername>, <username>, <password>, and <databasename> with the appropriate values for your deployment.

    https://www.youtube.com/watch?v=HOsk13R20AY

    Please comment below if you have any issues.

    Regards,

    Oury

    1 person found this answer helpful.

  2. Navarathina Raja, Arun Kumar 0 Reputation points
    2023-08-29T08:20:18.1233333+00:00

    Hi Oury,

    Thank you for your assistance. I was able to resolve the issue. I had to whitelist my IP address in order to get the access.


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.