Blog Post

Azure Database Support Blog
1 MIN READ

Quickly test connectivity from Azure Website to SQL DB

Azure-DB-Support-Team's avatar
Azure-DB-Support-Team
Copper Contributor
Mar 14, 2019
First published on MSDN on Mar 14, 2017
In case you have an Azure Website and you need to confirm that your website can reach SQL Database service here is a quick and simple way to test it:

1) navigate to Kudu (it can be accessed at https://{yourwebsitename}. scm .azurewebsites.net )

(Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites)



2) open CMD that it’s located under ‘Debug console’ menu



3) run tcpping against your server using: tcpping {servername} .database.windows.net:1433



you will see something like this:





If you don’t see successful attempts something is wrong, please open a new support request so we can help you.
Published Mar 14, 2019
Version 1.0
  • atulram's avatar
    atulram
    Brass Contributor

    What if I am using a Linux-based app service plan, which command will help me, troubleshoot connectivity.

  • bookofdaniel's avatar
    bookofdaniel
    Copper Contributor

    Thanks for the response But I believe `tcpping` will not be sufficient enough to test the database connectivity, better to use a posh script as below.

     

    Note: upload the posh script to Azure web app using Kudo `Zip Push Deploy` or vs code editor in portal. then execute thescript as `Powershell -File ".\<ScriptFileName.ps1>`

    # Define the necessary variables
    $serverName = "test.database.windows.net"
    $databaseName = "test"
    $username = "<your username>"
    $password = "<your password>"
    
    # Construct the connection string
    $connectionString = "Server=tcp:$serverName,1433;Initial Catalog=$databaseName;Persist Security Info=False;User ID=$username;Password=$password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
    
    # Load the .NET assembly
    Add-Type -AssemblyName "System.Data"
    
    # Create a new SQL connection
    $connection = New-Object System.Data.SqlClient.SqlConnection
    $connection.ConnectionString = $connectionString
    
    # Open the connection
    $connection.Open()
    
    # Create a new SQL command
    $command = $connection.CreateCommand()
    $command.CommandText = "SELECT DB_NAME()"
    
    # Execute the command and read the results
    $reader = $command.ExecuteReader()
    while ($reader.Read()) {
        Write-Output $reader[0]
    }
    
    # Close the reader and the connection
    $reader.Close()
    $connection.Close()

     

    If connectivity is success, it will return the database name.

     

    Thank you.