Sql server 活动任务SSI中的自定义日志记录

Sql server 活动任务SSI中的自定义日志记录,sql-server,excel,ssis,error-logging,Sql Server,Excel,Ssis,Error Logging,我在SSIS包中面临两个问题。我拥有的SSIS包有一个活动任务,该任务根据我的要求格式化excel工作表,并将其保存为另一个文件modified.xlsx。然后在我的数据流任务中使用该文件来处理数据并将其上载到数据库表。 此软件包在我的本地系统中运行良好,但当我在SQL server上创建计划作业以运行此软件包时,它会失败,并显示一般错误消息“Microsoft(R)SQL server Execute package Utility Version 11.0.5058.0 for 64位版权(

我在SSIS包中面临两个问题。我拥有的SSIS包有一个活动任务,该任务根据我的要求格式化excel工作表,并将其保存为另一个文件modified.xlsx。然后在我的数据流任务中使用该文件来处理数据并将其上载到数据库表。 此软件包在我的本地系统中运行良好,但当我在SQL server上创建计划作业以运行此软件包时,它会失败,并显示一般错误消息“Microsoft(R)SQL server Execute package Utility Version 11.0.5058.0 for 64位版权(C)Microsoft Corporation。保留所有权利。开始时间:12:06:55 PM错误:2016-04-01 12:06:57.06代码:0x00000001源代码:脚本任务描述:调用目标引发异常。结束错误DTExec:包执行返回DTSER_失败(1)。开始时间:12:06:55 PM结束时间:12:06:57 PM经过时间:1.563秒。包执行失败。步骤失败。“

为了获得更详细的错误消息,我尝试为活动任务设置日志记录。 我将日志配置为将事件的日志条目写入CSV文件,如下面的屏幕截图所示。

我为包启用了日志记录,并检查了个人任务。在活动任务中,我添加了Dts.Log(“,0,字节);跟踪任何异常(如果有),并记录每个步骤

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
}
public分部类ScriptMain:Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
字节[]字节=新字节[0];
公共图书馆
{
日志信息(“”);
日志消息(“更新错误包执行开始于::”+DateTime.Now.ToLongTimeString());
日志消息(“将包配置值加载到本地变量”);
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);
尝试
{
foreach(工作簿.工作表中的Excel.Worksheet临时工作表)
{
日志消息(“用于检查工作表名称的循环”);
如果(((Excel.Worksheet)(tempSheet)).Name.Contains(“测试”))
{
if(File.Exists(saveLoc))
{
文件。删除(saveLoc);
}
//创建(saveLoc);
tempSheet.Select();
工作簿.SaveAs(saveLoc);
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(临时表);
}
workbook.Save();
workbook.Close();
excel.Quit();
日志消息(“退出Excel工作表”);
System.Runtime.InteropServices.Marshal.ReleaseComObject(工作簿);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
日志消息(“发布excel对象”);
}
捕获(例外情况除外)
{
日志消息(“异常:+ex.InnerException”);
System.Runtime.InteropServices.Marshal.ReleaseComObject(工作簿);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
}
Dts.TaskResult=(int)ScriptResults.Success;
}
#区域脚本结果声明
/// 
///这个枚举在这个类的范围内提供了一个方便的速记来设置
///脚本的结果。
/// 
///此代码是自动生成的。
/// 
枚举脚本结果
{
Success=Microsoft.SqlServer.Dts.Runtime.dtsesecresult.Success,
Failure=Microsoft.SqlServer.Dts.Runtime.dtsesecresult.Failure
};
#端区
#将区域日志消息发送到包日志文件/表。
公共无效日志消息(字符串strLogMsg)
{
Log(strLogMsg,0,字节);
}
#端区
}
但是当我运行包时,日志文件没有更新。日志文件仅包含以下内容:

字段:事件、计算机、操作员、源、源ID、executionid、开始时间、结束时间、数据代码、数据字节、消息 有人能帮我理解我在这里缺少什么吗?此外,在SQL server中,作业失败可能是什么问题?

为什么不记录? 这里是有趣的部分,这是我多年来与SSI打交道所能想到的最好的部分
Dts.Log
是非常无用的,至少如果您希望它显示在SSIS内置的日志记录功能中

相反,更改对Dts.Events.Fire的Dts.Log调用,例如

然后,在上面的详细信息选项卡中,确保已选中
OnInformation
事件(这也假定您已将包配置为跟踪所有信息)

最后,如果您没有实际单击“提供者和日志”选项卡中的按钮,它将不会登录到表中

为什么它不起作用? 程序包不工作,因为您正在处理Excel,错误消息指定您正在64位模式下运行

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

除非您已经做了一些事情来明确地使64位Excel在此服务器上工作,否则它将无法工作。相反,在SQLA中
bool fireAgain = false;
Dts.Events.FireInformation(0, "This gest logged", "My long description here", string.Empty, 0, ref fireAgain);