【发布时间】:2016-07-21 17:44:58
【问题描述】:
我的 SSIS 包中存在两个问题。我拥有的 SSIS 包有一个活动任务,可根据我的要求格式化 Excel 工作表并将其保存为不同的文件 modified.xlsx。然后在我的数据流任务中使用该文件来处理数据并将数据上传到数据库表。 这个包在我的本地系统中运行良好,但是当我在我的 SQL 服务器上创建一个计划作业来运行这个包时,它失败并出现一般错误消息“Microsoft (R) SQL Server Execute Package Utility Version 11.0.5058.0 for 64-bit Copyright (C) Microsoft Corporation。保留所有权利。开始时间:下午 12:06:55 错误:2016-04-01 12:06:57.06 代码:0x00000001 源:脚本任务描述:调用目标引发了异常。结束错误 DTExec:包执行返回 DTSER_FAILURE (1)。开始:下午 12:06:55 完成:下午 12:06:57 经过:1.563 秒。包执行失败。步骤失败。"
为了获得更详细的错误消息,我尝试为活动任务设置日志记录。 我将日志配置为将事件的日志条目写入 CSV 文件,如下面的屏幕截图所示。
我也启用了包日志记录并检查了个人任务。在活动任务中,我添加了 Dts.Log("",0,bytes);跟踪任何异常(如果有)并记录每个步骤。
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
}
但是当我运行包时,日志文件没有更新。日志文件只包含以下内容:
字段:事件、计算机、操作员、来源、sourceid、executionid、开始时间、结束时间、数据代码、数据字节、消息
有人可以帮助我了解我在这里缺少什么进行日志记录吗?另外,作业在 SQL Server 中失败可能是什么问题?
【问题讨论】:
标签: sql-server excel ssis error-logging