在活动任务SSIS中自定义日志logging

我在SSIS包中遇到了两个问题。 我所拥有的SSIS包有一个活动任务,按照我的要求格式化一个Excel工作表,并将其另存为一个不同的文件modified.xlsx。 这个文件然后用于我的数据stream任务来处理和上传数据到数据库表。 这个软件包在我的本地系统中完美地工作,但是当我在我的SQL服务器上创build一个计划的作业来运行这个软件包时,它失败,出现一般错误消息“Microsoft(R)SQL Server执行软件包实用程序版本11.0.5058.0 (C)Microsoft Corporation。保留所有权利。开始date:12:06:55错误:2016-04-01 12:06:57.06代码:0x00000001来源:脚本任务描述:exception被调用的目标抛出。结束错误DTExec:程序包执行返回DTSER_FAILURE(1)。开始:12:06:55 PM完成:12:06:57 PM已用:1.563秒。程序包执行失败,步骤失败。

为了得到更详细的错误消息,我尝试设置活动任务的日志logging。 我将日志loggingconfiguration为将事件的日志条目写入CSV文件,如下面的屏幕截图所示。 在这里输入图像描述 在这里输入图像描述

我启用了包的日志logging和检查个人的任务。 在活动任务中,我添加了Dts.Log(“”,0,bytes); 跟踪任何exception,如果还有任何logging每个步骤。

public partial class ScriptMain:Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { byte[] bytes = new byte[0]; public void Main() { LogMessages(""); LogMessages("Update Bug package execution started at :: " + DateTime.Now.ToLongTimeString()); LogMessages("Loading package configuration values to local variables."); FileName = Convert.ToString(Dts.Variables["User::ExcelFileName"].Value); SourceFileLocation = Convert.ToString(Dts.Variables["User::SourceFileLoc"].Value); SourceFileName = Path.Combine(SourceFileLocation, FileName); saveLoc = Path.Combine(SourceFileLocation, "ModifiedExcel.xlsx"); var excel = new Excel.Application(); var workbook = excel.Workbooks.Open(SourceFileName); try { foreach (Excel.Worksheet tempSheet in workbook.Worksheets) { LogMessages("For loop to check sheet names"); if (((Excel.Worksheet)(tempSheet)).Name.Contains("Test")) { if (File.Exists(saveLoc)) { File.Delete(saveLoc); } //File.Create(saveLoc); tempSheet.Select(); workbook.SaveAs(saveLoc); } System.Runtime.InteropServices.Marshal.ReleaseComObject(tempSheet); } workbook.Save(); workbook.Close(); excel.Quit(); LogMessages("Quit Excel sheet"); System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); LogMessages("Release excel objects"); } catch(Exception ex) { LogMessages("Exception: " + ex.InnerException); System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel); } Dts.TaskResult = (int)ScriptResults.Success; } #region ScriptResults declaration /// <summary> /// This enum provides a convenient shorthand within the scope of this class for setting the /// result of the script. /// /// This code was generated automatically. /// </summary> enum ScriptResults { Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure }; #endregion #region Log messages to package log files/table. public void LogMessages(string strLogMsg) { Dts.Log(strLogMsg, 0, bytes); } #endregion } 

但是,当我运行包日志文件不会更新。 日志文件只包含以下内容:

字段:事件,计算机,操作员,源,源ID,执行ID,开始时间,结束时间,数据码,数据,消息

有人可以帮助我了解我在这里失踪logging? 另外,在SQL服务器中失败的问题可能是什么?

为什么不logging?

这里有一个有趣的部分,就像我在处理SSIS的这些年里所能够发挥的最好的一样。 Dts.Log是相当无用的,至less如果你想它显示在内置到SSIS中的日志工具。

相反,将您的Dts.Log调用更改为Dts.Events。 火,例如

 bool fireAgain = false; Dts.Events.FireInformation(0, "This gest logged", "My long description here", string.Empty, 0, ref fireAgain); 

然后,在上面的Details选项卡中,确保已经检查了OnInformation事件(这也假设你已经configuration了包来跟踪它)

在这里输入图像说明

最后,如果实际上没有单击“提供程序和日志”选项卡中的button,它将不会login到表

为什么它不工作?

该包不能正常工作,因为您正在处理Excel,并且错误消息指定您正在以64位模式运行。

Microsoft(R)SQL Server执行包实用程序版本11.0.5058.0(适用于64位)

除非你已经做了一些明确的64位Excel在这个服务器上工作,这是行不通的。 相反,在SQL代理作业中,您需要指定此任务以32位模式运行。

也可以看看

为什么在Visual Studio中运行SSIS加载时,我的ODBC连接失败,而在使用“执行包实用程序”运行相同的程序包时,却无法运行