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);
}
}
}
ファイル 'savePath'の許可を確認してください。 –