c# - 在 .net core 3.0 上运行集成服务 SSIS

标签 c# sql-server ssis etl .net-core-3.0

我们正在将一个 WPF 应用程序移植到 .net 核心,但我们有点卡在了 SSIS 部分。以前我们使用 Microsoft.SqlServer.Management.Sdk.SfcMicrosoft.SqlServer.Smo 使用此代码运行 SSIS:

    public void SSISUpload()
    {
        string targetServerName = "server";
        string folderName = "Project1Folder";
        string projectName = "Integration Services Project";
        string packageName = "SSISPackage/Package.dtsx";

        // Create a connection to the server
        string sqlConnectionString = "Data Source=" + targetServerName +
            ";Initial Catalog=master;Integrated Security=SSPI;";
        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

        IntegrationServices integrationServices = new IntegrationServices(sqlConnection);
        Catalog catalog = integrationServices.Catalogs["SSISDB"];
        CatalogFolder folder = catalog.Folders[folderName];
        ProjectInfo project = folder.Projects[projectName];
        PackageInfo package = project.Packages[packageName];

        // Run the package
        package.Execute(false, null);
    }

但是,上述引用与 .NET Framework 相关,似乎没有与 .net 核心或标准的绑定(bind)。我们尝试使用 Microsoft.SqlServer.SqlManagementObjects ,它确实具有 standard2.0 绑定(bind),但并没有真正翻译 1-1(类不存在)并且似乎没有任何关于如何从 .net 核心/标准运行 SSIS 的在线信息。有人设法做到这一点吗?

最佳答案

您可以使用不同的方法从 C# .net 核心执行 SSIS 包:

使用 Transact-SQL 命令

您可以简单地使用 SQLCommand 来执行 SSIS 包,而不是使用 Microsoft.SqlServer.SqlManagementObjects,例如:

Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
    @execution_id=@execution_id OUTPUT,
    @folder_name=N'Deployed Projects',
      @project_name=N'Integration Services Project1',
    @use32bitruntime=False,
      @reference_id=Null
EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO

您可以引用以下链接了解更多信息:

使用 DTEXEC 实用程序

另一种选择是使用 Process.Start执行 DTEXEC 应用程序的方法,该应用程序与 SQL Server 一起安装。例如:

Process p = new Process();

// Redirect the output stream of the child process.

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe";
p.StartInfo.Arguments = "/ISServer \"\SSISDB\Project1Folder\Integration Services Project1\Package.dtsx\" /Server \"localhost\"";
p.Start();
Debug.WriteLine(p.StandardOutput.ReadToEnd());
p.WaitForExit();

更多信息,您可以引用以下链接:

关于c# - 在 .net core 3.0 上运行集成服务 SSIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56559649/

相关文章:

java - 如何在 hibernate 中以特定顺序创建表列?

ssis - BIDS "Start Debugging"按钮不工作

c# - 如何将NameValueCollection转换为XML?

sql - SQL Server是否默认在表的所有列上创建非聚集索引

asp.net - 添加 Pooling=True 和 Integrated Security 会产生什么后果?

azure - 由于网关离线而无法启动复制,如何运行我的管道?

c# - 升级 DTS 包后出现 COMException

c# - 在 IIS 中部署 Web 服务?

c# - Microsoft Word 自动化/互操作 Win32 API 问题

c# - 从 Linq 中的 Select 查询中查找索引