使用 C# 执行 SSIS 包时出错 [英] Error executing SSIS package using C#

查看:49
本文介绍了使用 C# 执行 SSIS 包时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 C# 执行一个非常简单的 SSIS 包.

I try to execute a very simple SSIS Package using C#.

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

This package works fine when starting directly in Visual Studio 2015. The name of the SSIS package is "Lesson 1.dtsx".

我尝试使用带有以下代码的 C# 开始此过程:

I try to start this process using C# with the following code:

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", 包由于错误 0xC0011008从 XML 加载错误.没有更详细的错误信息.

"Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException", The package failed to load due to error 0xC0011008 "Error loading from XML. No further detailed error information.

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

The exception occurs in line: ssisPackage = app.LoadPackage(pkgLocation,null);

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

I added two DLLs as references in this project:

Microsoft.SqlServer.DTSRuntimeWrap.dll

Microsoft.SqlServer.ManagedDTS.dll

有人可以帮我吗?

推荐答案

除了我收到关于混合模式的错误之外,我没有任何问题,因为它针对 4.0 版的框架运行 2.0 版.因此,如果这不起作用,您的 ssis 包中可能有错误.否则尝试制作一个新的 ssis-packages,它基本上什么都不做,看看你是否成功.

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. So if this doesnt work you proberbly has an error in your ssis-package. Otherwise try to make a new ssis-packages which basically does nothing and see if you get success.

这是我的代码的样子:

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;
        }
    }
}

这就是我需要在 app.Config 中更正的内容:

And this is what i needed to correct in 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>

这篇关于使用 C# 执行 SSIS 包时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆