简体   繁体   English

在 C# .NET 中运行 SSIS package

[英]Running SSIS package in C# .NET

I am trying to run an SSIS package from a simple console app.我正在尝试从一个简单的控制台应用程序运行 SSIS package。 Unfortunately I am stuck on some errors`不幸的是,我遇到了一些错误`

       using System;
       using System.Collections.Generic;
       using System.Linq;
       using System.Text;
       using System.Threading.Tasks;
       using Microsoft.SqlServer.Management.IntegrationServices;
       using System.Data.SqlClient;

         namespace SSIStutorial
     {
class Program
{
    static void Main(string[] args)
    {
        // Variables
        string targetServerName = "localhost";
        string folderName = "Projects";
        string projectName = "SSIS Tutorial";
        string packageName = "Lesson 1.dtsx";

        // Create a connection to the server
        string sqlConnectionString = "Data Source = cgol1793109; Initial Catalog = TEST; Integrated Security=True;";
        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

        // Create the Integration Services object
        IntegrationServices integrationServices = new IntegrationServices(sqlConnection);

        // Get the Integration Services catalog
        Catalog catalog = integrationServices.Catalogs["SSISDB"];

        // Get the folder
        CatalogFolder folder = catalog.Folders[folderName];

        // Get the project
        ProjectInfo project = folder.Projects[projectName];

        // Get the package
        PackageInfo package = project.Packages[packageName];

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

I get the following while instantiating the IntegrationServices object of the type IntegrationServices.在实例化 IntegrationServices 类型的 IntegrationServices object 时,我得到以下信息。 I get the following error.我收到以下错误。

System.MissingMethodException HResult=0x80131513 Message=Method not found: 'Void Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection..ctor(System.Data.SqlClient.SqlConnection)'. System.MissingMethodException HResult=0x80131513 消息=找不到方法:'无效 Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection..ctor(System.Data.SqlClient.SqlConnection)'。 Source=Microsoft.SqlServer.Management.IntegrationServices StackTrace: at Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices..ctor(SqlConnection sqlConnection) at SSIStutorial.Program.Main(String[] args) in C:\Users\kokoro\source\repos\SSIStutorial\Program.cs:line 26 Source=Microsoft.SqlServer.Management.IntegrationServices StackTrace: 在 Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices..ctor(SqlConnection sqlConnection) 在 SSIStutorial.Program.Main(String[] args) 在 C:\Users\kokoro\source\ repos\SSIStutorial\Program.cs:第 26 行

Had the same issue with my console app.我的控制台应用程序有同样的问题。 Followed all the steps on Microsoft docs and it didn't work, got exactly the same error as you Method not found: 'Void Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection..ctor(System.Data.SqlClient.SqlConnection)' .按照微软文档上的所有步骤,它没有工作,得到与找不到方法完全相同的错误:'Void Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection..ctor(System.Data.SqlClient.SqlConnection) ' .

The Microsoft docs solution doesn't work on a Console App (.NET Core), it only works on a Console App (.NET Framework). Microsoft docs 解决方案不适用于控制台应用程序 (.NET Core),它仅适用于控制台应用程序 (.NET Framework)。

I guess you are trying to run in on a Console App (.NET Core)?我猜您正试图在控制台应用程序(.NET Core)上运行? I changed mine to .NET Framework and it worked.我将我的更改为 .NET 框架并且它有效。

Referring to the official documentation , the steps you used to define a connection and to instantiate the IntegrationServices object are correct.参考官方文档,您用于定义连接和实例化 IntegrationServices object 的步骤是正确的。 This means that the issue is caused by the connection string.这意味着问题是由连接字符串引起的。 Try to remove the additional spaces, edit the Integrated security parameter, and use the master database as the Initial catalog:尝试删除额外的空格,编辑 Integrated security 参数,并使用 master 数据库作为初始目录:

string sqlConnectionString = "Data Source=cgol1793109;Initial Catalog=master;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

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

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