23

Is it possible to test whether a database is hosted on SQL Azure? I am looking at SqlAzureExecutionStrategy for EF6 and only want to apply if the database is actually SQL Azure database.

Currently I am testing if App is running within Azure. However we are looking at allowing clients to host DB themselves so would like some way to identify if DB is a SQL Server or Azure SQL.

Assume EF won't know as it is hiding the implementation details.

Could just have a config setting I guess. Just wondered if it was technically possible.

1
  • 1
    Can't you just run SELECT @@version - it will be something like Microsoft SQL Azure (RTM) – 11.0.1465.26 Aug 10 2011 22:54:49 Copyright (c) Microsoft Corporation Commented Feb 5, 2014 at 16:13

2 Answers 2

42

Updated August 2021 to align with updated documentation

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

http://technet.microsoft.com/en-us/library/ms174396.aspx

Sign up to request clarification or add additional context in comments.

Comments

20

I've been using the same function as gvee, ServerProperty(), but with a different property name:

IF ServerProperty('Edition') = 'SQL Azure'
    PRINT 'true'

For me, this is easier to read and also self-documenting.

1 Comment

I was using this code as well, but then I found a case where it didn't work because of collation issue. Check dba.stackexchange.com/questions/317945/…

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.