以编程方式检测 SQL Server 版本

发布于 2024-07-14 13:23:44 字数 263 浏览 4 评论 0原文

我将 C# 与 SMO 结合使用,并尝试检测我正在连接的 SQL Server 版本(例如企业版、标准版)。 我知道如何获取版本信息,但这只能告诉我 SQL Server 的版本(例如,SQL Server 2008 与 SQL Server 2005)。

有谁知道如何获得实际的产品版本(例如企业版、标准版)?

我需要此信息,因为某些 SQL Server 功能仅供企业使用。 因此,我可以尝试调用它们并捕获异常,但我更喜欢预先检测。

谢谢!

I'm using C# with SMO and attempting to detect what edition of SQL Server (e.g., enterprise, standard) I'm connecting to. I know how to get the version information, but that only tells me what version of SQL Server (e.g., SQL Server 2008 vs SQL Server 2005).

Does anyone know how to get the actual product edition (e.g., enterprise, standard)?

I need this information because some SQL Server features are only enterprise. Thus, I could just try to call them and catch the exception, but I'd much prefer an upfront detection.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风苍溪 2024-07-21 13:23:45

我一直使用 @@Version (例如 SELECT @@Version 并在代码中操作结果),但这篇文章看起来很方便;
http://support.microsoft.com/kb/321185

使用 SERVERPROPERTY 的唯一问题,根据链接...这不适用于旧版本的 SQL Server。

I've always used @@Version (eg. SELECT @@Version and manipluted the result in code), but this article looks pretty handy;
http://support.microsoft.com/kb/321185

The only issue with using SERVERPROPERTY, as per the link... is that this won't work with older version of SQL Server.

傲鸠 2024-07-21 13:23:45
select @@version

返回版本和哪个版本。 这里:

Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
    Nov 24 2008 13:01:59 
    Copyright (c) 1988-2005 Microsoft Corporation
    Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
select @@version

Returns version and which edition. Here:

Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
    Nov 24 2008 13:01:59 
    Copyright (c) 1988-2005 Microsoft Corporation
    Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
假情假意假温柔 2024-07-21 13:23:45

检查注册表。 这个问题有一个很好的方法,您可以从PowerShell脚本中进行调整:

如何使用 Powershell 检查 SQL Server 版本?

Check the registry. This question had a good method you could adapt from the PowerShell script:

How do I check for the SQL Server Version using Powershell?

橙幽之幻 2024-07-21 13:23:44
SELECT  SERVERPROPERTY('productversion'), 
        SERVERPROPERTY ('productlevel'), 
        SERVERPROPERTY ('edition')

在我的系统上返回

9.00.1399.06, RTM, Express Edition

似乎这种技术仅适用于 SQL Server 2000 或更高版本,如果您的任何数据库是 7.0 或更低,您将不得不使用 @@Version 并按照其他人发布的方式操作结果

SELECT  SERVERPROPERTY('productversion'), 
        SERVERPROPERTY ('productlevel'), 
        SERVERPROPERTY ('edition')

on my system returns

9.00.1399.06, RTM, Express Edition

It seems this technique only works on SQL Server 2000 or later, if any of your databases are 7.0 or less, you'll have to use @@Version and manipulate the results as others have posted

黑凤梨 2024-07-21 13:23:44

看来您可以通过 SMO 和服务器对象来完成此操作。 有像 Information.Edition 这样的属性,看起来它应该做你想要的事情。

It looks like you might be able to do it via SMO and the Server object. There are properties like Information.Edition which looks like it should do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文