I am working on some packages. I got some error message: the binary code for the script is not found. please open the script in the designer by clicking......
And I searched online, some information says I just need to delete the existing script task and create a new one. And copy the code to the new task, but I did it, still have some errors. (I am using the visual studio 2012). Anyone please help me find something that caused the issue. By the way, this script task worked find before. Don't know when the issue started. Thank you so much!!
Here is the scripts:
region Help: Introduction to the script task
/* The Script Task allows you to perform virtually any operation that can be accomplished in
* a .Net application within the context of an Integration Services control flow.
*
* Expand the other regions which have "Help" prefixes for examples of specific ways to use
* Integration Services features within this script task. */
endregion
region Namespaces
using System;
using System.Data;
//using System.Drawing;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
using ST_d1e76887aff94a898f859b7c2677b241.ReportServiceReference;
using ClosedXML.Excel;
endregion
namespace ST_d1e76887aff94a898f859b7c2677b241
{
/// <summary>
/// ScriptMain is the entry point class of the script. Do not change the name, attributes,
/// or parent of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region Help: Using Integration Services variables and parameters in a script
/* To use a variable in this script, first ensure that the variable has been added to
* either the list contained in the ReadOnlyVariables property or the list contained in
* the ReadWriteVariables property of this script task, according to whether or not your
* code needs to write to the variable. To add the variable, save this script, close this instance of
* Visual Studio, and update the ReadOnlyVariables and
* ReadWriteVariables properties in the Script Transformation Editor window.
* To use a parameter in this script, follow the same steps. Parameters are always read-only.
*
* Example of reading from a variable:
* DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;
*
* Example of writing to a variable:
* Dts.Variables["User::myStringVariable"].Value = "new value";
*
* Example of reading from a package parameter:
* int batchId = (int) Dts.Variables["$Package::batchId"].Value;
*
* Example of reading from a project parameter:
* int batchId = (int) Dts.Variables["$Project::batchId"].Value;
*
* Example of reading from a sensitive project parameter:
* int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();
* */
#endregion
#region Help: Firing Integration Services events from a script
/* This script task can fire events for logging purposes.
*
* Example of firing an error event:
* Dts.Events.FireError(18, "Process Values", "Bad value", "", 0);
*
* Example of firing an information event:
* Dts.Events.FireInformation(3, "Process Values", "Processing has started", "", 0, ref fireAgain)
*
* Example of firing a warning event:
* Dts.Events.FireWarning(14, "Process Values", "No values received for input", "", 0);
* */
#endregion
#region Help: Using Integration Services connection managers in a script
/* Some types of connection managers can be used in this script task. See the topic
* "Working with Connection Managers Programatically" for details.
*
* Example of using an ADO.Net connection manager:
* object rawConnection = Dts.Connections["Sales DB"].AcquireConnection(Dts.Transaction);
* SqlConnection myADONETConnection = (SqlConnection)rawConnection;
* //Use the connection in some code here, then release the connection
* Dts.Connections["Sales DB"].ReleaseConnection(rawConnection);
*
* Example of using a File connection manager
* object rawConnection = Dts.Connections["Prices.zip"].AcquireConnection(Dts.Transaction);
* string filePath = (string)rawConnection;
* //Use the connection in some code here, then release the connection
* Dts.Connections["Prices.zip"].ReleaseConnection(rawConnection);
* */
#endregion
XLPageOrientation landscape = XLPageOrientation.Landscape;
XLPageOrientation portrait = XLPageOrientation.Portrait;
XLWorkbook wbFrom;
Byte[] results;
/// <summary>
/// This method is called when this script task executes in the control flow.
/// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
/// To open Help, press F1.
/// </summary>
public void Main()
{
int[] zoom = new int[3];
XLPageOrientation[] orientation = new XLPageOrientation[3];
//Create Object of ReportExecutionService class
//Dts.Events.FireWarning(9999, "GenerateFiles", "Starting Script", "", 1);
Dts.Variables["User::Progress"].Value = "Starting script";
ReportExecutionService rs = new ReportExecutionService();
//Set the export format
string format = Dts.Variables["$Package::ReportFormat"].Value.ToString();
//Set empty variables required for Render report method
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
Warning[] warnings = null;
string[] streamIDs = null;
string deviceInfo = null;
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
//rs.Url = @"http://portal.usmmllc.com/_vti_bin/ReportServer/ReportExecution2005.asmx";
rs.Url = Dts.Variables["$Project::ReportExecutionServiceUrl"].Value.ToString();
//Load Weekly Census Report
//Dts.Events.FireWarning(9999, "GenerateFiles", "Before loading Executive Sum report", "", 1);
Dts.Variables["User::Progress"].Value = "loading Weekly Census report";
//rs.LoadReport("http://portal.usmmllc.com/BIReports/BI/RVU/WeeklyCensusReport.rdl", null);
rs.LoadReport(Dts.Variables["$Package::WeeklyCensusReportUrl"].Value.ToString(), null);
//Dts.Events.FireWarning(9999, "GenerateFiles", "After loading Executive Sum report", "", 1);
//Create Parameters and assign their value
Dts.Variables["User::Progress"].Value = "setting parameters for Weekly Census report";
ParameterValue[] paramvalSummaryDX = new ParameterValue[4];
paramvalSummaryDX[0] = new ParameterValue();
paramvalSummaryDX[0].Name = "Month";
paramvalSummaryDX[0].Value = Dts.Variables["$Package::ReportMonth"].Value.ToString();
paramvalSummaryDX[1] = new ParameterValue();
paramvalSummaryDX[1].Name = "Year";
paramvalSummaryDX[1].Value = Dts.Variables["$Package::ReportYear"].Value.ToString();
paramvalSummaryDX[2] = new ParameterValue();
paramvalSummaryDX[2].Name = "RollingVisit";
paramvalSummaryDX[2].Value = Dts.Variables["$Package::TrendingWeeksTable"].Value.ToString();
paramvalSummaryDX[3] = new ParameterValue();
paramvalSummaryDX[3].Name = "TrendingWeeksGraph";
paramvalSummaryDX[3].Value = Dts.Variables["$Package::TrendingWeeksGraph"].Value.ToString();
//Add list of execution parameters
rs.SetExecutionParameters(paramvalSummaryDX, "en-us");
//Execute the Weekly Census Report
//Dts.Events.FireWarning(9999, "GenerateFiles", "Before executing Executive Sum report", "", 1);
Dts.Variables["User::Progress"].Value = "executing Weekly Census report";
results = rs.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
//Dts.Events.FireWarning(9999, "GenerateFiles", "After executing report", "", 1);
////Save the file
//Dts.Variables["User::Progress"].Value = "saving unformatted Weekly Census report";
//using (FileStream stream = File.Open(Dts.Variables["User::ReportFullName"].Value.ToString(), FileMode.Create, FileAccess.Write))
//{
// stream.Write(results, 0, results.Length);
// stream.Close();
//}
//Dts.Events.FireWarning(9999, "GenerateFiles", "Finished Executive Sum report", "", 1);
Dts.Variables["User::Progress"].Value = "processing Weekly Census report";
zoom[0] = 100;
zoom[1] = 100;
zoom[2] = 100;
orientation[0] = portrait;
orientation[1] = portrait;
orientation[2] = portrait;
ProcessExcel("PrintFormat", zoom, orientation);
Dts.Variables["User::Progress"].Value = "finishing the whole report";
ProcessExcel("Finish", zoom, orientation);
Dts.TaskResult = (int)ScriptResults.Success;
}
/// <summary>
/// perform Excel requests:
/// "PrintFormat" - set print format for individual tabs
/// "Finish" - close application and clean-up
/// </summary>
private void ProcessExcel(string requestType, int[] wsZoom, XLPageOrientation[] orientation)
{
string currentResult = "";
//Dts.Events.FireWarning(9999, "GenerateFiles", "Before Try", "", 1);
try
{
switch (requestType)
{
case "PrintFormat":
currentResult = " case \"PrintFormat\": opening wbFrom";
wbFrom = new XLWorkbook(new MemoryStream(results));
for (int j = 1; j <= wbFrom.Worksheets.Count; j++)
{
// Dts.Events.FireWarning(9999, "GenerateFiles", "Before ws", "", 1);
currentResult = " case \"Add\": opening worksheet number " + j.ToString();
using (IXLWorksheet ws = wbFrom.Worksheet(j))
{
// Dts.Events.FireWarning(9999, "GenerateFiles", "Before ws.Copy", "", 1);
currentResult = " case \"PrintFormat\": copying worksheet number " + j.ToString();
currentResult = " case \"PrintFormat\": formatting worksheet number " + j.ToString();
FormatWorksheet(wbFrom.Worksheet(j), orientation[j - 1], wsZoom[j - 1]);
}
// Dts.Events.FireWarning(9999, "GenerateFiles", "Finished ws.Copy", "", 1);
}
break;
case "Finish":
currentResult = " case \"Finish\": activatig the first worksheet";
wbFrom.Worksheet(1).SetTabActive();
currentResult = " case \"Finish\": closing wbFrom";
wbFrom.SaveAs(Dts.Variables["User::ReportFullName"].Value.ToString());
break;
}
}
catch (Exception ex)
{
Dts.Events.FireError(9999, "Error Excel Copy Workseets", ex.Message, "", 1);
Dts.TaskResult = (int)ScriptResults.Failure;
Dts.Variables["User::Progress"].Value = Dts.Variables["User::Progress"].Value.ToString() + currentResult;
throw;
}
}
private void FormatWorksheet(IXLWorksheet ws, XLPageOrientation orient, int zoom)
{
ws.SetShowGridLines(false);
ws.PageSetup.PagesTall = 1;
ws.PageSetup.PagesWide = 1;
ws.PageSetup.SetPageOrientation(orient);
ws.PageSetup.Margins.Bottom = Convert.ToDouble(Dts.Variables["$Package::MarginBottom"].Value.ToString());
ws.PageSetup.Margins.Top = Convert.ToDouble(Dts.Variables["$Package::MarginTop"].Value.ToString());
ws.PageSetup.Margins.Left = Convert.ToDouble(Dts.Variables["$Package::MarginLeft"].Value.ToString());
ws.PageSetup.Margins.Right = Convert.ToDouble(Dts.Variables["$Package::MarginRight"].Value.ToString());
ws.SheetView.SetView(XLSheetViewOptions.Normal);
ws.SheetView.SetZoomScale(zoom);
}
#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
}
}