报告工作的工作不同,我的本地机器
问题描述:
这里是问题的简要说明:报告工作的工作不同,我的本地机器
我有写在C#
与HTML/CSS
和TSQL
语言的脚本,该脚本应该分发生成的报告对我们每个团队成员来说,当我在本地计算机上测试时,每个人都可以获得电子邮件,但是如果我将其作为我们服务器上的工作计划,我们只有少数人能够获得(我们有一张表用于记录发送的电子邮件,并且日志记录步骤也是脚本中的TSQL存储过程),我已检查过表格,并且没有关于缺少接收者的此类数据记录,仅限于那些获得电子邮件的人员,这意味着存储过程无法工作对于那些没有收到邮件的会员,以及b elow是登录表格并发送电子邮件的代码
public void Main()
{
...code above
try
{
...code above
if (SendMail(sSubject, sBody))
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception e)
{
//error handling
}
}
public bool SendMail(string sSubject, string sMessage)
{
try
{
string sEmailSendTo = Dts.Variable["ProjRespEmail"].Value.ToString();
string sEmailSendFrom = Dts.Variables["SqlEmail"].Value.ToString();
if (Dts.Variables["StrClientName"].Value.ToString() != "")
{
using (SqlConnection sqlCon = new SqlConnection("connection name"))
{
sqlCon.Open();
using (SqlCommand sqlCmd = sqlCon.CreateCommand())
{
sqlCmd.CommandText = "name";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add(new SqlParameter("SendingMachine", Environment.MachineName));
sqlCmd.Parameters.Add(new SqlParameter("Recipients", sEmailSendTo));
sqlCmd.Parameters.Add(new SqlParameter("Subject", sSubject));
sqlCmd.Parameters.Add(new SqlParameter("Body", sMessage));
sqlCmd.ExecuteNonQuery();
}
}
}
Dts.Variables["ProjRespEmail"].Value = "";
Dts.Variables["StrProjResponsible"].Value = "";//SqlEmail
Dts.Variables["SqlEmail"].Value = "";
Dts.Variables["StrClientName"].Value = "";
return true;
}
catch (Exception ex)
{
//error handling
return false;
}
}
任何建议将不胜感激。
答
代码中的问题部分是TaskResult始终设置为Success。删除下面的行:
try
{
...code above
if (SendMail(sSubject, sBody))
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
//Remove this, because it overwrites the actions from above
//Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception e)
{
//error handling
}
这将至少允许任务失败,因此您可以捕获任何错误。根据您的描述,听起来像proc可能与您的本地计算机到服务器的版本不同,因为收件人变量的大小可能不同,并且会截断列表。
为什么不使用SSRS订阅,而不是使用SSIS来发送报告? –