0
我的C#Windows服務自動發送電子郵件。在發送之前,我需要將我的報告轉換並附加爲PDF。我得到下面當我嘗試了PDF導出就行了異常:Windows服務無法打開連接
cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, savePath);
在一個窗口失敗相同的代碼運行正常打開連接(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);
}
}
}
檢查文件'savePath'權限。 –