Crystal Report in a Web application fails to log on to SQL Server (319264)
The information in this article applies to:
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft SQL Server 2000 (all editions) 8.0
- Microsoft SQL Server 2000 (all editions) SP2
- Microsoft SQL Server 2005 Standard Edition
- Microsoft SQL Server 2005 Developer Edition
- Microsoft SQL Server 2005 Enterprise Edition
- Microsoft SQL Server 2005 Express Edition
- Microsoft SQL Server 2005 Workgroup
This article was previously published under Q319264 SYMPTOMS When you use Microsoft SQL Server 2000 or SQL Server 2005 to obtain live data for a
Crystal Report in a Visual Studio .NET Web application, the Crystal Report
fails to log on to the database. This occurs even if you provide accurate
credentials at design time. You receive the following error message in your Web
browser: Server Error in '/Crystal' Application.
----------------------------------------------------------- Logon
failed.
Description: 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: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon
failed. CAUSE For security reasons, the SQL Server password is not
persisted in the Crystal Report at run time. RESOLUTION To resolve this problem, you must deliver the connection
information to each database table individually to access the database as a
whole. To deliver the connection information, add variables to the code of your
Microsoft Visual C# .NET Web Form as follows:
// Add namespaces at top.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
//Crystal Report Variables
CrystalReport1 crReportDocument = new CrystalReport1();
//'CrystalReport1' must be the name the CrystalReport
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
//Crystal Report Properties
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
CrystalDecisions.CrystalReports.Engine.Table crTable; Then, use following code sample to add the logic in the Page_Load method of your Web Form:
crConnectionInfo.ServerName = "EnterServerNameHere";
crConnectionInfo.DatabaseName = "EnterDatabaseNameHere";
crConnectionInfo.UserID = "EnterUserIDHere";
crConnectionInfo.Password = "EnterPasswordHere";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
foreach(CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
CrystalReportViewer1.ReportSource = crReportDocument;
For the preceding code to run successfully, you must type your
ServerName, DatabaseName, UserID, and Password. The Crystal Report in this
example (CrystalReport1.rpt) is set up by using OLE DB and SQL Server
authentication. For more detailed information about how to create a
Web application that uses the Crystal Reports viewer (CRViewer), see the "Steps
to Reproduce the Behavior" portion of the "More Information" section. Note Crystal Decisions handles all support questions and support
issues concerning Crystal Reports for Visual Studio .NET, except installation
questions. See the "References" section of this article for procedures to
follow for help with support questions and support issues. STATUSThis
behavior is by design.REFERENCES
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
317789
Licensing and support for Crystal Reports for Visual Studio .NET
300985 How to configure user and group access on an intranet in Windows NT 4.0 or Windows 2000
For more information about Report Binding Options
for Web Forms Viewers, visit the following Web site:
The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.
Modification Type: | Major | Last Reviewed: | 1/2/2006 |
---|
Keywords: | kbvs2002sp1sweep kbBug kbDebug kbDeployment kbIDEProject kbMaintMode kbprb kbSecurity kbSysAdmin KB319264 kbAudDeveloper |
---|
|