Another problem that I've seen mentioned a lot on the message boards involves binding directly to the data via SQL, a Stored Procedure, a view, etc. The ASP.NET page gives out this error: Exception Details: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed.
This one is pretty hard to troubleshoot. When I got this error, I would step through the code in Visual Studio in debug mode. In doing this, I discover no errors are encountered when stepping through the initial code. I then tried using a technique to log onto all tables in the report documents tables collection. The code to do this is below:
Dim oReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
oReport.Load(reportName)
DoCRLogin(oReport)
Public Sub DoCRLogin(ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim _applyLogin As New ApplyCRLogin
' use ApplyLogin object to apply login info to all tables in CR object
_applyLogin._dbName = "Northwind"
_applyLogin._passWord = "CrystalUser"
_applyLogin._serverName = "(local)"
_applyLogin._userID = "CrystalUser"
_applyLogin.ApplyInfo(oRpt)
' clean up
_applyLogin = Nothing
End Sub
Public Class ApplyCRLogin
Public _dbName As String
Public _serverName As String
Public _userID As String
Public _passWord As String
Public Sub ApplyInfo(ByRef _oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
Dim oCRDb As CrystalDecisions.CrystalReports.Engine.Database = _oRpt.Database
Dim oCRTables As CrystalDecisions.CrystalReports.Engine.Tables = oCRDb.Tables
Dim oCRTable As CrystalDecisions.CrystalReports.Engine.Table
Dim oCRTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim oCRConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
oCRConnectionInfo.DatabaseName = _dbName
oCRConnectionInfo.ServerName = _serverName
oCRConnectionInfo.UserID = _userID
oCRConnectionInfo.Password = _passWord
For Each oCRTable In oCRTables
oCRTableLogonInfo = oCRTable.LogOnInfo
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo
oCRTable.ApplyLogOnInfo(oCRTableLogonInfo)
Next
End Sub
End Class
The class ApplyCRLogin has the method that applies the login to each table in the report. This is instantiated via the DoCRLogin method, which sets the user name, password, server name and database. In this instance, the login info is the same for all. A different method would have to be created to accommodate different tables to login. This seems to solve a lot of login problems similar to what I've mentioned.
If that still doesn't solve the issue, I've seen folks change from OLEDB to ODBC drivers, along with this login technique. That seems to solve some tricky login problems as well.
Summary
These are a couple of login problems I have seen on the mailing lists. Keep in mind the object oriented nature of the CR document when working on login problems. That may help in solving login problems not covered by this article. I hope this helps, and keep on coding!