4

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?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Suresh Kharod
  • 51
  • 1
  • 7
  • possible duplicate of [How can I tell what edition of SQL Server runs on the machine?](http://stackoverflow.com/questions/2070396/how-can-i-tell-what-edition-of-sql-server-runs-on-the-machine) – MeanGreen Apr 20 '15 at 13:32
  • possible duplicate of [How can I determine installed SQL Server instances and their versions?](http://stackoverflow.com/questions/141154/how-can-i-determine-installed-sql-server-instances-and-their-versions) – JimmyB Apr 20 '15 at 13:44

4 Answers4

3

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')

JimmyB
  • 12,101
  • 2
  • 28
  • 44
3

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
2

Here some code that get installed MS SQL Server Editions on server to console based on @marc_s answer:

//This line open Registry with x64 View from x86 process. Usually SQL server installed in x64 edition, otherwise you should check x86
var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var msSQLServer = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
var instances = (string[])msSQLServer.GetValue("InstalledInstances");

foreach (var instance in instances)
{
    var insNames = localMachine.OpenSubKey(@"Software\Microsoft\Microsoft SQL Server\Instance Names\SQL");
    var realNameInstanse = (string)insNames.GetValue(instance);
    var sqlEditionRegistry = localMachine.OpenSubKey(string.Format(@"Software\Microsoft\Microsoft SQL Server\{0}\Setup", realNameInstanse));
    var edition = (string)sqlEditionRegistry.GetValue("Edition");
    Console.WriteLine("Instance {0}, RealName {2}, - Edition: {1}", instance, edition, realNameInstanse);
}

Here is edition list based on list at the end of this article:

  • Standard Edition

  • 64-bit Edition

  • Express Edition

  • Developer Edition

  • Enterprise Edition

  • Workgroup Edition

  • Standard

  • Analysis Services

  • Developer

  • Enterprise

  • Enterprise Evaluation

  • Express

  • Express with Advanced Services

  • Integration Services

  • Datacenter

  • Reporting Services

  • Standard Edition for Small Business

  • Web

  • Workgroup

  • Business Intelligence

  • Enterprise Core

teo van kot
  • 12,350
  • 10
  • 38
  • 70
0

To check sql server version, you can query for @@version.

execute select @@version

The output consists of:

  1. SQL server version
  2. SQL server edition
  3. Latest patch installed
  4. Computer's processor (32 bit or 64 bit)
Daniel
  • 14,004
  • 16
  • 96
  • 156