使用 C# 执行 SSIS 包时出错

我尝试SSIS使用C#.


在 Visual Studio 2015 中直接启动时,此包运行良好。SSIS 包的名称是“Lesson 1.dtsx”。


我尝试使用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");

            }


        }

    }

}

执行此代码时,出现异常:


“Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException”,由于错误 0xC0011008“从 XML 加载错误。没有更详细的错误信息,导致程序包加载失败。


异常发生在: ssisPackage = app.LoadPackage(pkgLocation,null);


我在这个项目中添加了两个 DLL 作为引用:


Microsoft.SqlServer.DTSRuntimeWrap.dll


Microsoft.SqlServer.ManagedDTS.dll

有人能帮助我吗?


森栏
浏览 300回答 1
1回答

四季花海

除了我收到关于混合模式的错误之外,我没有任何问题,因为它针对 4.0 版的框架运行 2.0 版。因此,如果这不起作用,您的 ssis 包中可能有错误。否则尝试制作一个新的 ssis-packages,它基本上什么都不做,看看你是否成功。这是我的代码的样子:using Microsoft.SqlServer.Dts.Runtime;namespace ConsoleApplication8{&nbsp; &nbsp; class Program&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; static void Main(string[] args)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string pkgLocation;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Package pkg;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application app;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DTSExecResult pkgResults;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyEventListener eventListener = new MyEventListener();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pkgLocation =&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @"C:\Users\thoje\Documents\Visual Studio 2015\Projects\Integration Services Project8\Integration Services Project8\Package37.dtsx";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app = new Application();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pkg = app.LoadPackage(pkgLocation, eventListener);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pkgResults = pkg.Execute(null,null,eventListener,null,null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(pkgResults.ToString());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.ReadKey();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; class MyEventListener : DefaultEvents&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; public override bool OnError(DtsObject source, int errorCode, string subComponent,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string description, string helpFile, int helpContext, string idofInterfaceWithError)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Output Error Message&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}这就是我需要在 app.Config 中纠正的内容:<?xml version="1.0" encoding="utf-8" ?><configuration>&nbsp; &nbsp; <startup useLegacyV2RuntimeActivationPolicy="true">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />&nbsp; &nbsp; </startup></configuration>
打开App,查看更多内容
随时随地看视频慕课网APP