c#Window服务中的问题

时间:2013-07-18 10:31:42

标签: c# sql-server reporting-services windows-services

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

代码示例

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文件”

开始服务

直接打电话

查找打孔

是的,必须发送

是的,必须发送,

我在GetConnectionOfReportServer。

我正在尝试。 //在此行之后应该打印“我在尝试结束”

打电话给Susseccfully。

再次调用 OnElapsedTime 事件。

0 个答案:

没有答案