the1.9gpaProgrammer
the1.9gpaProgrammer

Reputation: 115

Determine if a database is an azure database

Is it ok to assume that if the server name ends with "database.windows.net" that the database is hosted on azure?

I tried executing this code on my azure db:

SELECT CASE ServerProperty('EngineEdition')
         WHEN 1 THEN 'Personal'
         WHEN 2 THEN 'Standard'
         WHEN 3 THEN 'Enterprise'
         WHEN 4 THEN 'Express'
         WHEN 5 THEN 'SQL Database'
         WHEN 6 THEN 'Azure Synapse Analytics'
         WHEN 8 THEN 'Azure SQL Managed Instance'
         WHEN 9 THEN 'Azure SQL Edge'
         WHEN 11 THEN 'Azure Synapse serverless SQL pool'
         ELSE 'Unknown'
       END

But it returned "SQL Database"...

How can I reliably discern if a database or sql server is hosted on azure?

I should be writing the code to determine this in c#

right now it might be something like:

if (serverName.Contains("database.windows.net"))
   {
            //is on azure 
   }
   else
   {
            //is not hosted on azure
   }

Upvotes: 1

Views: 2025

Answers (1)

Bhavani
Bhavani

Reputation: 5297

I tried with your code I also got the same issue. Image for reference:

enter image description here

We can replace 'Azure SQL Database' in place of 'SQL Database'.
I used below code to determine the database:

SELECT  CASE
WHEN  ServerProperty('Edition') =  'SQL Azure'
     THEN  'Azure SQL Database'
     ELSE  'Not Azure SQL Database'  END  AS server_version;

enter image description here

Upvotes: 2

Related Questions