Skip to main content

Connecting to Azure SQL Database

You can connect to the Azure SQL Database used by the Management Server in several ways:

  1. Via Query Editor on Azure portal.

  2. With your favorite tool such as Azure Data Studio.

  3. With sqlcmd

    1. If not installed yet, install sqlcmd from https://github.com/microsoft/go-sqlcmd/releases

      apt-get install bzip2
      wget https://github.com/microsoft/go-sqlcmd/releases/download/v1.8.2/sqlcmd-linux-amd64.tar.bz2 -O /tmp/sqlcmd.tar.bz2
      tar -xjf /tmp/sqlcmd.tar.bz2 -C /usr/local/bin/
      chmod +x /usr/local/bin/sqlcmd
    2. On your machine: you must have own an account on the database server. For example:

      sqlcmd -S <SQL server URL> -d <database name> \
      --authentication-method=ActiveDirectoryDeviceCode
    3. From the SSH session to the App Service container: you can use application’s managed identity.

      1. System-assigned:

        env $(cat /proc/1/environ | tr '\0' '\n' | grep '^IDENTITY_' | xargs -0) \
        sqlcmd -S <SQL server URL> -d <database name> \
        --authentication-method=ActiveDirectoryManagedIdentity
      2. User-assigned: add -U flag set to client ID of the managed identity (or user value from the DB connection string):

        env $(cat /proc/1/environ | tr '\0' '\n' | grep '^IDENTITY_' | xargs -0) \
        sqlcmd -S <SQL server URL> -d <database name> \
        --authentication-method=ActiveDirectoryManagedIdentity \
        -U <ideneity-client-id>