简体   繁体   English

使用C#执行SSIS包时出错

[英]Error executing SSIS package using C#

I try to execute a very simple SSIS Package using C# . 我尝试使用C#执行一个非常简单的SSIS包。

This package works fine when starting directly in Visual Studio 2015. The name of the SSIS package is "Lesson 1.dtsx". 直接在Visual Studio 2015中启动时,此程序包运行良好。SSIS程序包的名称为“ Lesson 1.dtsx”。

I try to start this process using C# with the following code: 我尝试使用C#和以下代码启动此过程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace run_ssis_project
{
    public class ExecuteSSIS
    {
        public void exePackage()
        {
            String pkgLocation = @"C:\SSIS Tutorial\Lesson 1.dtsx";
            Microsoft.SqlServer.Dts.Runtime.Package ssisPackage;
            Microsoft.SqlServer.Dts.Runtime.Application app;
            Microsoft.SqlServer.Dts.Runtime.DTSExecResult result;

            app = new Microsoft.SqlServer.Dts.Runtime.Application();
            ssisPackage = app.LoadPackage(pkgLocation,null);

            result = ssisPackage.Execute();

            if(result == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine("Failure");
            }

        }
    }
}

When executing this code, I get an exception: 执行此代码时,出现异常:

"Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException", The package failed to load due to error 0xC0011008 "Error loading from XML. No further detailed error information. “ Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException”,由于错误0xC0011008“从XML加载错误,因此无法加载包。没有更多详细的错误信息。

The exception occurs in line: ssisPackage = app.LoadPackage(pkgLocation,null); 发生在行中的异常:ssisPackage = app.LoadPackage(pkgLocation,null);

I added two DLLs as references in this project: 我在该项目中添加了两个DLL作为参考:

Microsoft.SqlServer.DTSRuntimeWrap.dll

Microsoft.SqlServer.ManagedDTS.dll

Can someone help me please? 有人能帮助我吗?

I didnt have any problem besides that i got an error about mix mode because it was running version 2.0 against a framework with version 4.0. 除了混合模式错误外,我没有任何问题,因为它针对版本4.0的框架运行版本2.0。 So if this doesnt work you proberbly has an error in your ssis-package. 因此,如果这不起作用,则说明您的sis-package中存在错误。 Otherwise try to make a new ssis-packages which basically does nothing and see if you get success. 否则,尝试制作一个新的ssis-packages,它基本上什么都不做,看看是否成功。

This is how my code looks like: 这是我的代码的样子:

using Microsoft.SqlServer.Dts.Runtime;


namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {

            string pkgLocation;
            Package pkg;
            Application app;
            DTSExecResult pkgResults;
            MyEventListener eventListener = new MyEventListener();

            pkgLocation =
              @"C:\Users\thoje\Documents\Visual Studio 2015\Projects\Integration Services Project8\Integration Services Project8\Package37.dtsx";
            app = new Application();
            pkg = app.LoadPackage(pkgLocation, eventListener);
            pkgResults = pkg.Execute(null,null,eventListener,null,null);

            Console.WriteLine(pkgResults.ToString());
            Console.ReadKey();
        }
    }


    class MyEventListener : DefaultEvents
    {
        public override bool OnError(DtsObject source, int errorCode, string subComponent,
               string description, string helpFile, int helpContext, string idofInterfaceWithError)
        {
            // Output Error Message
            Console.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);
            return false;
        }
    }
}

And this is what i needed to correct in app.Config: 这就是我需要在app.Config中更正的内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>

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

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