c#窗口服务中的问题

c#窗口服务中的问题,c#,sql-server,reporting-services,windows-services,C#,Sql Server,Reporting Services,Windows Services,在我的窗口服务中,当我从manage运行窗口服务时,ScheduledService文件不包含“Get Connection”。我认为GetConnectionForReportServer中存在问题,可能需要更多时间。 当我调试时,它运行良好 代码示例 protected override void OnStart(string[] args) { TraceService("start service"); timer = ne

在我的窗口服务中,当我从manage运行窗口服务时,ScheduledService文件不包含“Get Connection”。我认为GetConnectionForReportServer中存在问题,可能需要更多时间。 当我调试时,它运行良好

代码示例

protected override void OnStart(string[] args)
        {
            TraceService("start service");
            timer = new System.Timers.Timer(1000);
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            timer.Interval = 90000;
            timer.Enabled = true;

        }
 protected override void OnStop()
        {
            TraceService("stopping service");
        }

 private void OnElapsedTime(object source, ElapsedEventArgs e)
        {

           time_elapsed();
            TraceService("Another entry at " + DateTime.Now);

        }
  private void time_elapsed()
        {           
            TraceService("Call susseccfully");
            GetConnectionOfReportServer();//The problem is here.
            TraceService("Get Connection");
            DailyReportFile = getReportFrmServer(reportName, param);
        }
    public void GetConnectionOfReportServer()
        {
           TraceService("I am in GetConnectionOfReportServer "); //**Edit part**

            try
            {
                NetworkCredential credential = new NetworkCredential("administrator", "epass@123");
                this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;
                this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
                this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://xxx.xxx.xxx.xxx/ReportServer");

            }
            catch (Exception ex)
            {

            }
        }
 private void TraceService(string content)
        {
            FileStream fs = new FileStream(@"c:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);

            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(content);
            sw.Flush();
            sw.Close();
        }
编辑方法

  public void GetConnectionOfReportServer()
        {
            TraceService("I am in GetConnectionOfReportServer.");
            try
            {
                TraceService("I am in Try.");
                //NetworkCredential credential = new NetworkCredential("administrator", "espl@123","");
                NetworkCredential credential = new NetworkCredential("administrator", "esmart@123");
                this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;

                //select where the report should be generated with the report viewer control or on the report server using the SSRS service.
                this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
                this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://xxx.xxx.xxx.xxx/ReportServer");
                TraceService("I am atTry end");




            }

            catch (Exception ex)
            {
                TraceService(ex.StackTrace);

            }
            finally
            {
                TraceService("I am in finally block");
            }
        }
但是当我看到我的“ScheduledService文件”

启动服务

打电话给Susseccfull

找到潘趣

是的,我必须发送

是的,我必须发送

我在GetConnectionOfReportServer中

我正在努力在这一行之后,应该打印“我在尝试结束”

给susseccfully打电话


再次调用OneLassedTime事件。

您的捕获块为空。添加
ex.Message;ex.stackTrace
来计算错误消息并跟踪易出错的行。是的,我在函数的第一行添加了TraceService(),还添加了finally块,但不知道为什么控件没有出现在函数中……否。添加一些类似以下内容的内容
catch(Exception ex){TraceService(ex.Message();ex.StackTrace(););}