Hello,
I am developing a web app that has reports created on VS 2019 and run fine from developer mode, but when I publish the website I get "Database logon failed" Error. Database server is on different server that development and production machine.
The error is throwing in line
cryRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Note that I have the same version of crystal reports installed to developer and production machine and aspnet_client folder is on wwwroot and 32-bit Application is enabled on Application Pool.
I also changed Identity to Administrator (Application Pool --> Advance Settings) and back to ApplicationPoolIdentity, since it didn't work.
I try connecting from IIS Server to database server using the reports credentials to check if I have access and there is access.
Development machine: Windows 10, Visual Studio 2019, Crystal Reports v4.0.30319
Production machine: Windows Server 2012 R2, Crystal Reports v4.0.30319
What could be causing this? Thank you in advance.
This is my code:
- public void sendEmail(int id)
- {
- ReportDocument cryRpt = new ReportDocument();
- TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
- TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
- ConnectionInfo crConnectionInfo = new ConnectionInfo();
- Tables CrTables;
- cryRpt.Load(@"C:\temp\rep1.rpt");
- crConnectionInfo.ServerName = "server";
- crConnectionInfo.DatabaseName = "db";
- crConnectionInfo.UserID = "username";
- crConnectionInfo.Password = "pass";
- CrTables = cryRpt.Database.Tables;
- foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
- {
- crtableLogoninfo = CrTable.LogOnInfo;
- crtableLogoninfo.ConnectionInfo = crConnectionInfo;
- CrTable.ApplyLogOnInfo(crtableLogoninfo);
- }
- cryRpt.SetParameterValue("@ID", id);
- emailCreator(from, to, subject, body, "Attachment.pdf", cryRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
- }