I am facing two issues in my SSIS package. The SSIS package I have has an active task that formats an excel sheet as per my requirement and saves it as a different file, modified.xlsx. This file is then used in my data flow task to process and upload data to database tables. This package works perfectly in my local system, but when I created a scheduled job on my SQL server to run this package it fails with the generic error message "Microsoft (R) SQL Server Execute Package Utility Version 11.0.5058.0 for 64-bit Copyright (C) Microsoft Corporation. All rights reserved. Started: 12:06:55 PM Error: 2016-04-01 12:06:57.06 Code: 0x00000001 Source: Script Task Description: Exception has been thrown by the target of an invocation. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 12:06:55 PM Finished: 12:06:57 PM Elapsed: 1.563 seconds. The package execution failed. The step failed."
To get a more detailed error message i tried to set up logging for the active task. I configured logging to write log entries for events to a CSV file as in the below screen shot.
I enabled logging for package and checked individuals tasks as well. In active tasks, I added Dts.Log("",0,bytes); to keep track of any exception if any also to log each steps.
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
}
But when i run the package the log file is not updated. The log file just contains the following :
Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message
Can someone please help me understand what I am missing here for logging? Also, what could be the issue for the job to fail in SQL server?