[英]Error executing SSIS package using C#
我嘗試使用C#
執行一個非常簡單的SSIS
包。
直接在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
有人能幫助我嗎?
除了混合模式錯誤外,我沒有任何問題,因為它針對版本4.0的框架運行版本2.0。 因此,如果這不起作用,則說明您的sis-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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.