使用C#执行SSIS包时出错

问题描述 投票:1回答:1

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

有谁可以帮助我吗?

c# sql-server visual-studio-2015 ssis
1个回答
0
投票

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

这是我的代码的样子:

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中纠正的内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.