2016-09-09 7 views
0

C#Windowsサービスが電子メールを自動的に送信します。送信する前に、私のレポートをPDFに変換して添付する必要があります。私はPDFをエクスポートしようとすると、下の行に例外を取得:Windowsサービスが接続を開けません。

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

は、Windowsフォームアプリケーションで正しく

接続(ODBC)を開くには、同じコードの機能を失敗しました。どうすれば解決できますか?

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接続を最初に確認してください –

関連する問題