2016-09-09 2 views
0

C# Windows 서비스가 자동으로 전자 메일을 보냅니다. 전송하기 전에 보고서를 PDF로 변환하여 첨부해야합니다. 윈도우에서 동일한 코드 기능이 제대로 연결 (ODBC)Windows 서비스가 연결을 열지 못합니다.

를 열지 못했습니다

cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, savePath); 

응용 프로그램을 형성 : 나는 PDF를 내보낼 때 아래 라인에 예외를 얻을. 이 문제를 어떻게 해결할 수 있습니까?

public void GenerateReport(string rptpath, int no) 
{ 
    try 
    { 
    string savePath = ConfigurationManager.AppSettings["Savepath"]; 
    ReportDocument cr = new ReportDocument(); 

    cr.Load(rptpath); 

    TableLogOnInfo logInfo = new TableLogOnInfo(); 

    Tables crTables = cr.Database.Tables; 

    foreach (Table crTable in crTables) 
    { 
     logInfo.ConnectionInfo.UserID = "sa"; 
     logInfo.ConnectionInfo.DatabaseName = "SunVue"; 
     logInfo.ConnectionInfo.ServerName = "SunVue"; 
     logInfo.ConnectionInfo.Password = "sa"; 
     logInfo.ConnectionInfo.IntegratedSecurity = false; 
     crTable.ApplyLogOnInfo(logInfo); 

     DateTime enddate = DateTime.Today; 
     DateTime startdate = enddate.AddDays(-7); 
     string reportFormula = string.Empty; 

     if (no == 201) 
     { 
     cr.SetParameterValue("DateRange",startdate.ToString("dd'/'MM'/'yyyy") 
           + " to " + enddate.ToString("dd'/'MM'/'yyyy")); 

     reportFormula = "{spilInvNum.OrderDate} in DateTime (" 
         + startdate.Year.ToString() + "," 
         + startdate.Month.ToString() + "," + 
         + startdate.Day.ToString() + ", 00, 00, 00) to DateTime (" 
         + enddate.Year.ToString() + "," 
         + enddate.Month.ToString() + "," 
         + enddate.Day.ToString() + ", 00, 00, 00)"; 

     //reportFormula = "{spilInvNum.OrderDate} in Date(" + startdate.Year.ToString() + "," + startdate.Month.ToString() + "," + startdate.Day.ToString() + ") " + " to DateTime (" + enddate.Year.ToString() + "," + enddate.Month.ToString() + "," + enddate.Day.ToString() + ") " + " and {spilInvNum.DocState} <> 6 and {spilInvNum.DocType} = 4 and {spilInvNum.AccountID} <> 2592"; 
     cr.RecordSelectionFormula = reportFormula; 
     } 
     cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, savePath); 
     WriteToFile(savePath); 
    } 
    } 
} 
+1

'savePath'권한을 확인하십시오. –

답변

0

OBDC에서 연결을 설정하는 방법.

  1. ODBC에서 stablishing 할 때 연결을 테스트하려고 했습니까?
  2. 보고서 마법사에서 어떻게 연결을 사용 했습니까? 생성 된 OBDC 사용? CR 마법사에 연결할 때 - 잘못된 연결이 생성 된 경우 약속해야합니다.
+0

위의 코드를 참조하십시오. –

+0

odbc 연결을 먼저 확인하십시오. –

관련 문제