简体   繁体   English

ssis包执行直接成功但通过c#代码失败

[英]ssis package execution succeeds directly but fails via c# code

I have the following code which seems to works OK for executing an SSIS package from c# BUT every time the variable "Resp" returns a Failure even if the package passes when I execute it directly in SSIS.我有以下代码,它似乎可以从 c# 执行 SSIS 包,但是每次变量“Resp”返回失败时,即使我直接在 SSIS 中执行它时包通过了。

Again, the package contains a Script component that writes to an SQL server table.同样,该包包含一个写入 SQL 服务器表的脚本组件。 All that works OK when the package is executed directly in SSIS but nothing happens when the same package is called via C# with the code below.当包直接在 SSIS 中执行时,一切正常,但当使用下面的代码通过 C# 调用同一个包时,没有任何反应。 I cant work out what I am doing wrong.我无法弄清楚我做错了什么。 help!帮助!

string packageLocation = @"c:\packageLocationPath";
Package pkg;
Application app;
app = new Application();
pkg = app.LoadPackage(packageLocation, null);
var Resp = pkg.Execute();

Detecting error检测错误

First you have to read the errors raised by the package.首先,您必须阅读包引发的错误。 There are two options to detect these errors:有两个选项可以检测这些错误:

(1) loop over errors (1) 循环错误

You can loop over the package errors by accessing Errors property.您可以通过访问 Errors 属性来遍历包错误。 As example:例如:

if(p.Errors.Count > 0){
    foreach(DtsError err in p.Errors){
        Messagebox.Show(err.Description);
    }
}

More information at:更多信息请访问:

(2) Enable logging from package (2) 从包启用日志记录

You can capture all errors, warning and information from a package by enabling logging option:您可以通过启用日志记录选项从包中捕获所有错误、警告和信息:


Possible failure causes可能的故障原因

  1. Make sure that if you are using windows authentication to connect to SQL, that the user account used to execute the application via C# is granted to make a connection.确保如果您使用 Windows 身份验证连接到 SQL,则用于通过 C# 执行应用程序的用户帐户被授予建立连接的权限。
  2. If the package is accessing a file system, make sure that the user has the required permissions to access these files如果包正在访问文件系统,请确保用户具有访问这些文件所需的权限

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

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