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?
SQL-Server似乎有一个内置函数SERVERPROPERTY
,因此您应该能够通过SQL查询服务器,如:
SELECT SERVERPROPERTY('EngineEdition')
You can look at the installed instances in the registry key:
Software\Microsoft\Microsoft SQL Server\InstalledInstances
This will contain all the installed instances, eg 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 eg 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
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
To check sql server version, you can query for @@version
.
execute select @@version
The output consists of:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.