Good Day,
I am using VS2015 to create an SSIS package which generates an email containing both text and a return dataset. The method that I found and am using sends the dataset values (more than one record) out as text using a ForEach Loop. It is working;
mostly.
my C# code is main():
Variables varCollection = null;
string header = string.Empty;
string message = string.Empty;
string footer = string.Empty;
Dts.VariableDispenser.LockForWrite("User::EmailMessage");
Dts.VariableDispenser.LockForWrite("User::EmailBody_P1");
Dts.VariableDispenser.LockForWrite("User::EmailBody_Footer");
Dts.VariableDispenser.LockForWrite("User::MaxSiteID");
Dts.VariableDispenser.LockForWrite("User::MaxWOGenDescr");
Dts.VariableDispenser.LockForWrite("User::MaxNewValue");
Dts.VariableDispenser.LockForWrite("User::MaxOldValue");
Dts.VariableDispenser.GetVariables(ref varCollection);
//Set the header message for the query result
if (varCollection["User::EmailMessage"].Value == string.Empty)
{
header = string.Format(varCollection["User::EmailBody_P1"] + "\n" + "\n");
//"Execute SQL task output sent using Send Email Task in SSIS:\n\n";
header += string.Format("{0}\t{1}\t\t\t{2}\t\t{3}\n", "Site ID", "WOGen Description", "Old Value", "New Value");
varCollection["User::EmailMessage"].Value = header;
}
//Format the query result with tab delimiters
message = string.Format("{0}\t{1}\t\t\t{2}\t\t\t{3}",
varCollection["User::MaxSiteID"].Value,
varCollection["User::MaxWOGenDescr"].Value,
varCollection["User::MaxOldValue"].Value,
varCollection["User::MaxNewValue"].Value);
footer = string.Format( "\n" + varCollection["User::EmailBody_Footer"]);
varCollection["User::EmailMessage"].Value = varCollection["User::EmailMessage"].Value + message + footer;
Dts.TaskResult = (int)ScriptResults.Success;
The results are ALMOST what I expect and look like this as received by email:
Microsoft.SqlServer.Dts.Runtime.Variable
Site ID WOGen Description Old Value New Value
CGCH PMWOGenGroup2Mo 60 60
Microsoft.SqlServer.Dts.Runtime.VariableKGH PMWOGenGroup1Mo 30 30
Microsoft.SqlServer.Dts.Runtime.VariablePHH PMWOGenGroup1MoB 0 0
Microsoft.SqlServer.Dts.Runtime.VariablePIMC PMWOGenGroup1Mo 30 30
Microsoft.SqlServer.Dts.Runtime.VariableSHMCPMWOGenGroup2Mo 60 60
Microsoft.SqlServer.Dts.Runtime.VariableSJH
PMWOGenGroup1Mo 30 30
Microsoft.SqlServer.Dts.Runtime.VariableSJMC PMWOGenGroup1Mo 30 30
Microsoft.SqlServer.Dts.Runtime.VariableSWMC PMWOGenGroup1MoB 36 36
Microsoft.SqlServer.Dts.Runtime.VariableUGMCPMWOGenGroup1Mo 30 30
Microsoft.SqlServer.Dts.Runtime.VariableSSC
PMWOGenGroup1MoB 0 0
Microsoft.SqlServer.Dts.Runtime.Variable
My issues are:
- The first line of the email reads Microsoft.SqlServer.DTS.Runtime.Variableand should be a line of TEXT that is defined in the SSIS Package Variable -- NOTE: It does read the to line feeds (\n) that I sent.
- The next section (looping through the data) reads the header row and the first row of data as expected. This is followed by: Microsoft.SQLServer.DTSRuntime.VariableDataElement, next data element... The data elements are correct. Why is the Microsoft... showing?
- The final line of the email is like the first. it reads Microsoft.SqlServer.DTS.Runtime.Variable and should be a line of TEXT that is defined in the SSIS Package Variable.
If I could just clean this up a bit, it would be perfect.
Thank you in advance for any guidance/help.
MT