Database logon failed when exporting Crystal Report to PDF

Posted on 2014-09-17
Last Modified: 2014-12-29
I have converted a ASP.NET 1.0 app to 4.0.  It is a simple app with only 3 pages and 4 reports.  For the most part the conversion went well and on both my development machine and the production machine I can run it, navigate between the pages, retrieve and update data from a SQL Server 2008 R2 database.  On the development machine I can also create Crystal Reports which are then exported to PDF.  On the production machine however when I try to do this I get this message:

Server Error in '/EslCalls' Application.


Database logon failed.

An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.

Exception Details:
System.Runtime.InteropServices.COMException: Database logon

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x8004100f): Database logon failed.] CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0 CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +362  [LogOnException: Database logon failed.] CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +909 CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +471 CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +772 CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) +185 CrystalDecisions.CrystalReports.Engine.FormatEngine.Export() +115 CrystalDecisions.CrystalReports.Engine.ReportDocument.Export() +80 EslCalls.Reports.MakePDFfile(ReportDocument crpt, String ReportName) in C:\WebApps\EslCalls\Reports.aspx.vb:158 EslCalls.Reports.btnSubmit_Click(Object sender, EventArgs e) in C:\WebApps\EslCalls\Reports.aspx.vb:97 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804  

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET

On my development machine:

     Windows 7
     IIS 7
     Visual Studio 2010
     Crystal Reports for Visual Studio 2010
     The reports had been developed in Crystal XI but they were imported in to VS 2010 converted and saved
    The app runs under a application pool I created that uses a network Windows account that has all the
    necessary permission on the SQL Server  objects.
     In the web.config file identity impersonate is set to true.

On the production machine:

     Windows Server 2012 R2
     IIS 8
     SAP Crystal Reports runtime engine for. NET Framework (64-bit)
    The app runs under a application pool I created that uses the same Windows account as on my
    development machine
     In the web.config file identity impersonate is set to true.

IIS and application are on one server and SQL Server is on another. The server that IIS is on is named Intranet02 and the Intranet02$ account has all the necessary permissions on the database objects.

The pertinent code:

Dim crpt As New ReportDocument()
crpt = New rptCategory()
ReportName = "Category"
MakeCrParameter(txtStartDate.Text, "@StartDate", crpt)
MakeCrParameter(txtEndDate.Text, "@EndDate", crpt)
FileName = MakePDFfile(crpt, ReportName)

Private Function MakePDFfile(ByVal crpt As ReportDocument, ByVal ReportName As String) As String
     Dim TodayFile As String = Month(Now) & Day(Now) & Year(Now)
     Dim FileName As String = ReportName & " " & Now.Month & "-" & Now.Day & "-" & Now.Year & "-" &
     Now.Second & ".pdf"
     Dim dfdo As New CrystalDecisions.Shared.DiskFileDestinationOptions()
     dfdo.DiskFileName = "C:\WebApps\EslCalls\Reports\" & FileName
     With crpt
          ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
          .ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
          .ExportOptions.DestinationOptions = dfdo
     End With
     MakePDFfile = FileName
     'Open a new window linked to the PDF file containing the report.  The window is resizable.
     Dim Script As String = "<Script language='javascript'>'/EslCalls/Reports/" + FileName + "','Reports','width=800,height=500,resizable=1')</script>"

     Page.ClientScript.RegisterStartupScript(Me.GetType(), "Session Timed Out", Script, False)
     'Clear the form after the report has been created
End Function

The error occurs at the line

Any suggestions would be greatly appreciated.
Question by:leskelly
  • 10
  • 5
LVL 18

Expert Comment

ID: 40328770
There is no code to set database connection. The only way this can work is if you set the report to use an ODBC connection with integrated security or if you use a database without password. Check if you have the ODBC DSN file on the server. You need to provide more information about the database and connection

Author Comment

ID: 40328797
Hello vasto,

Thanks for your speedy response.  The database connection is a OLE DB (ADO) connection set within the report.  I'm sure the connection is correct as I can verify it in Visual Studio and can open the report it VS and through the app on my development machine.

Author Comment

ID: 40328832
I have a report that doesn't connect to a database and it opens on the production machine.  It seems like it must be a permissions issue but I don't know what it would be as the app should be running under the same account on both my development and my production machine and the reports open on my development machine.
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.


Author Comment

ID: 40329003
I was thinking perhaps on the server the app was running under a different identity then I expected so I put Dim username As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
Response.Write("User = " & username)
right before the code that generates the report.  On both the production and development machines it shows the correct user account.
LVL 18

Expert Comment

ID: 40329071
If your OLE DB connection is set to use windows authentication then it might work for you , but you need to grant permissions in the database for the user which is running the website

Author Comment

ID: 40329108
In IIS I have set a user I created as the identity of the app pool the app is running under and have given this user permissions on the database.  This is the same on both machines so I'm thinking that is the user’s credentials that the report is using.

Author Comment

ID: 40329153
I'm trying to create a new Datasource Location for one of the reports hard coding in a User ID and password instead of using Integrated Security but when I click on Finish I get this message:

Login failed.
Details:ADO Error Code: 0x80040e4d
Source: Microsoft OLE DB Provider for SQL Server
Description:Login failed for user 'HRanon'.
SQL State: 42000
Native Error: 18456 [Database Vendor Code 18456]

This happens even if I use my user name and password which has administrative permissions on both server.
LVL 18

Expert Comment

ID: 40329159
You do not have any code that is going to set the report connection. When you run it locally it is using Windows authentication to get the data from the local database. When you run it on production this is not happening and report returns error. If you want to use username/password login you need to add code to set the connection

Author Comment

ID: 40329166
There is no local database.  Even when running the app on my development machine the data is coming from a network server.
LVL 18

Expert Comment

ID: 40329202
What I meant is that you were probably used Integrated security an this was not working on the website. When you tried to change this to use username and password it is failing because you do not have code to set the connection info . Crystal is not saving the password for security reasons , It should be set each time the report is run.

Author Comment

ID: 40329215
When setting a Datasource Location within the report, by going to Crystal Reports-Database-Set Datasource location, if Integrated Security is not check there are fields for user name and password.  This is where I'm getting the message I had posted above.
LVL 18

Expert Comment

ID: 40329329
Do you have subreports using different connection?

Author Comment

ID: 40330255
No there are no subreports in any of the reports.
LVL 100

Expert Comment

ID: 40330285
Crystal does not save the password with the report so you must provide the password when you run the report.

When running the reports do you get prompted for a password?
If not you need to provide the password through the code.


Accepted Solution

leskelly earned 0 total points
ID: 40331005
I opened a discussion on the SAP website and one of the Support Engineers there told me what the issue is.  I needed to have the SQL native client installed on the server.  Once we did that the reports opened as I expected with out the need for a user name or password.  Thanks for you suggestions.

Author Closing Comment

ID: 40338609
I got the answer from the SAP website.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question