0

I'm trying to configure an Azure pipeline where I create a copy of a production database to create a "pre-prod" environment.

After create that database I need to run some queries in the freshly created database. The problem is database is not available right away. As the process is automatic I need to know for how long I need to wait.

I put a wait step for 5 minutes but sometimes is not enough.

Thanks in advance

2 Answers 2

1

How about using a simple check of DB availability, through Az module, or CLI?

do {
  sleep 120
  $status = "Offline"
  try{
    $status = (Get-AzSqlDatabase -ResourceGroupName "resourcegroup01" -ServerName "server01"-DatabaseName "MyDataBase").Status
  }
  catch
  {
    "Database not available yet"
  }
} while ($status -ne "Online")
Sign up to request clarification or add additional context in comments.

4 Comments

I use your base idea to solve my problem (I already request some changes in your answer to match what I do). I use Azure PowerShell.
@Gelásio Can you share your changes here? I will help you update these changes into Oleh Tarasenko's answer.
I don't see any request for edit, @Gelásio can you please write what is need to be changed. Thank you!
I already try another time. I don't know why my first request for edit simply disappear. Here it is my second try: stackoverflow.com/review/suggested-edits/27175641
0

You can try to use the Azure portal's query editor to query an Azure SQL Database to check DB availability.

The query editor is a tool in the Azure portal for running SQL queries against your database in Azure SQL Database or data warehouse in Azure Synapse Analytics.

Note: The query editor uses ports 443 and 1443 to communicate. Ensure you have enabled outbound HTTPS traffic on these ports. You also need to add your outbound IP address to the server's allowed firewall rules to access your databases and data warehouses.

For more query editor considerations, please refer to this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.