Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the installed instance is full SQL Server or just SQL Server Express

Tags:

c#

sql-server

In one of my project, first I need to check whether SQL Server is installed on the machine or not. I am doing this with the code shown here:

 var sqlRegistry = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Microsoft SQL Server", true);

 if (sqlRegistry == null) 
 { }
 else 
 { }

But in the else part, I need to know whether the installed SQL Server is "only" SQL Server Express, or a full SQL Server edition.

How will I go for this?

like image 995
Suresh Kharod Avatar asked Feb 11 '23 09:02

Suresh Kharod


2 Answers

You can look at the installed instances in the registry key:

Software\Microsoft\Microsoft SQL Server\InstalledInstances

This will contain all the installed instances, e.g. on my system:

MSSQLSERVER
SQLEXPRESS

Go into this registry key with this value:

Software\Microsoft\Microsoft SQL Server\Instance Names\SQL

to get the actual instance name that you need in the next step.

Now if you go look at the registry key:

Software\Microsoft\Microsoft SQL Server\(InstanceName)\Setup\Edition

there you have a value of e.g. Express for a SQL Server Express, or Developer Edition or something else. That should tell you if you have Express or another, "full" edition of SQL Server

like image 163
marc_s Avatar answered Feb 12 '23 21:02

marc_s


SQL-Server seems to have a built-in function SERVERPROPERTY, so you should be able to query the server via SQL, like:

SELECT SERVERPROPERTY('EngineEdition')

like image 36
JimmyB Avatar answered Feb 12 '23 21:02

JimmyB