简体   繁体   English

报告服务器上的计划作业与我的本地计算机不同

[英]Reports job scheulded on server works different from my local machine

here is the brief description for the issue: 这是该问题的简要说明:

I have a script that written in C# with HTML/CSS and TSQL language, the script is supposed to distribute the generated report to each of our team member, when I test on my local machine, everyone could get the email, but if I scheduled it as a job on our server, only few of us could get (we have a table for logging the sent email, and the logging step is the TSQL Stored Procedure in the script,too), I've checked the table, and there is no such data records for missing recipient, only for those who got the email, which means the Stored Procedure did not work for those members who did not get the email, and below is the code for logging to the table and send out the email 我有一个用C#HTML/CSSTSQL语言编写的脚本,该脚本应该将生成的报告分发给我们的每个团队成员,当我在本地计算机上进行测试时,每个人都可以收到电子邮件,但是如果我计划了作为服务器上的一项工作,我们中只有少数人可以得到(我们有一个用于记录已发送电子邮件的表,并且记录步骤也是脚本中的TSQL存储过程),我已经检查了该表,没有丢失收件人的此类数据记录,仅适用于收到电子邮件的人员,这意味着存储过程不适用于未收到电子邮件的成员,以下是用于登录到表并发送电子邮件的代码

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;

            }
        }

Any suggestion would be much appreciated. 任何建议将不胜感激。

Part of the issue in the your code is that the TaskResult is always set to Success in the end. 您的代码中的部分问题是,最后总是将TaskResult设置为Success。 Remove the line noted below: 删除下面指出的行:

   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                
  }

This will at least allow the task to fail so you can capture any errors. 这至少将使任务失败,因此您可以捕获任何错误。 By your description, it sounds like the proc might differ from your local machine to the server's version in that the Recipients variable might differ in size and be truncating the list. 根据您的描述,听起来proc可能与本地计算机和服务器版本不同,因为Recipients变量的大小可能不同,并且会截断列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发送邮件在服务器上有效,但在我的本地计算机上无效 - sending mail works on server but not on my local machine ASP.NET 项目在 VS 运行时在本地运行,但不在本地计算机或服务器上的 IIS 上运行 - ASP.NET project works locally on build when VS is running but not on IIS on my local machine or my server .Ajax方法可在本地计算机上使用,但不能在服务器上使用 - .Ajax method works on local machine, but not on server 我的.net应用程序可在本地计算机上运行,​​但是从网络位置使用时失败 - My .net application works on local machine but fails when used from a network location asp.net CSS在我的本地计算机和远程计算机中有所不同 - asp.net css is different in my local machine and remote machine 使用C#.net应用程序访问活动目录中的不同域在本地计算机上工作,但在IIS服务器中托管时不能 - Access to different domain in active directory using C# .net application works in local machine but not when hosted in IIS server Ajax自动完成CSS在iis和服务器上工作正常,但在本地计算机上工作不正常 - Ajax Auto complete Css works fine in iis and the server but not in local machine 在本地机器上停止 Quartz 作业 - Stop Quartz Job on local machine C#Web API可在本地计算机上运行,​​但不能在服务器上运行 - C# Web API works on local machine but not on server 将文件夹从本地计算机复制到服务器中的文件夹 - to copy folders from local machine to folder in server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM