简体   繁体   English

如何检查已安装的实例是完整SQL Server还是仅SQL Server Express

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

In one of my project, first I need to check whether SQL Server is installed on the machine or not. 在我的一个项目中,首先我需要检查机器上是否安装了SQL Server。 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. 但是在else部分,我需要知道安装的SQL Server是“仅”SQL Server Express还是完整的SQL Server版本。

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. 在那里你有一个值,如Express for SQL Server Express,或Developer Edition或其他东西。 That should tell you if you have Express or another, "full" edition of SQL Server 这应该告诉您是否有Express或另一个“完整版”的SQL Server

Here some code that get installed MS SQL Server Editions on server to console based on @marc_s answer: 这里有一些代码可以在服务器上安装MS SQL Server Editions到基于@marc_s的控制台:

//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 64位版

  • 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 . 要检查sql server版本,可以查询@@version

execute select @@version

The output consists of: 输出包括:

  1. SQL server version SQL服务器版本
  2. SQL server edition SQL服务器版
  3. Latest patch installed 安装最新补丁
  4. Computer's processor (32 bit or 64 bit) 计算机的处理器(32位或64位)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM