首页 > 解决方案 > 如何使用 C# 找出安装在 SQL Server 中的 SSIS?

问题描述

我正在使用 C# 编写一个 Windows 窗体应用程序。我用

ssisServer = new IntegrationServices(ssisConnection); 

运行和使用 SSIS 包,但在运行包之前,我想确保用户在正确的系统中运行应用程序,并且 SQL Server 的 SQL Server 上有 SSIS。

如何在 C# 中查找服务器上是否安装了 SSIS?

标签: c#sql-serverssis

解决方案


检查 SQL Server Integration Services 服务是否在您连接的服务器上运行。

SQL Server        Service Name
SQL 2008          MsDtsServer100
SQL 2012          MsDtsServer110
SQL 2014          MsDtsServer120
SQL 2016          MsDtsServer130
SQL 2017          MsDtsServer140
SQL 2019          MsDtsServer150

服务的名称取决于您连接的 SQL Server 版本。例如,如果服务器是 SQL Server 2019,那么它将是 MsDtsServer150。您可以简单地检查服务是否存在并正在运行。

将 System.ServiceProcess 添加到您的项目引用中(它位于 .NET 选项卡上)。

using System.ServiceProcess;

ServiceController sc = new ServiceController("MsDtsServer150");

switch (sc.Status)
{
    case ServiceControllerStatus.Running:
        return "Running";
    case ServiceControllerStatus.Stopped:
        return "Stopped";
    case ServiceControllerStatus.Paused:
        return "Paused";
    case ServiceControllerStatus.StopPending:
        return "Stopping";
    case ServiceControllerStatus.StartPending:
        return "Starting";
    default:
        return "Status Changing";
}

推荐阅读