locked
How to resolve this problem with vb.net(asp.net);CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed. RRS feed

  • Question

  • User-1746687881 posted
    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. Topic ID: Q319264 Topic Title: Q319264 - PRB: Crystal Report in Web Application Fails to Log On to SQL Server URL: ms-help://MS.MSDNQTR.2003FEB.1028/enu_kbvstudionetkb/en-us/vstudionetkb/Q319264.htm Browser: Microsoft Internet Explorer 4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 1.0.3705) Comments: How to resolve this problem with vb.net(asp.net) This is my code: <%@ import namespace="CrystalDecisions.web"%> <%@ import namespace="CrystalDecisions.Shared"%> <%@ import namespace="CrystalDecisions.ReportSource"%> <%@ import namespace="CrystalDecisions.CrystalReports.Engine"%> <%@ import namespace="system.data.sqlclient"%> <%@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=9.1.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>??????</title> <!--#include file="opensqlserver.aspx"--> <script runat="server"> sub page_load(obj as object,e as eventargs) ''CrystalReport1' must be the name the CrystalReport ' dim crTableLogOnInfo as new TableLogOnInfo 'dim crConnectionInfo as new ConnectionInfo() '//Crystal Report Properties 'dim crDatabase as CrystalDecisions.CrystalReports.Engine.Database 'dim crTables as CrystalDecisions.CrystalReports.Engine.Tables 'dim crTable as CrystalDecisions.CrystalReports.Engine.Table 'crConnectionInfo.ServerName = "zhongsb" 'crConnectionInfo.DatabaseName = "project_manager" 'crConnectionInfo.UserID = "sa" 'crConnectionInfo.Password = "3" 'crDatabase = crReportDocument.Database 'crTables = crDatabase.Tables 'crTableLogOnInfo = crTable.LogOnInfo 'crTableLogOnInfo.ConnectionInfo = crConnectionInfo 'crTable.ApplyLogOnInfo(crTableLogOnInfo) role() bindreport() end sub sub bindreport() dim jobcatstr,jobnostr,sdatestr,edatestr,path,sqlstr as string jobcatstr=request("jobcatstr") jobnostr=request("jobnostr") sdatestr=request("sdatestr") edatestr=request("edatestr") if jobcatstr<>"" and jobnostr<>"" and sdatestr<>"" and edatestr<>"" then sqlstr="select * from viewcompt where jobcat like '%"& jobcatstr &"%' and jobno like '%"& jobnostr &"%' and AcutalComptDate between '"& sdatestr &"' and '"& edatestr &"'" elseif jobcatstr<>"" and sdatestr<>"" and edatestr<>"" then sqlstr="select * from viewcompt where jobcat like '%"& jobcatstr &"%' and AcutalComptDate between '"& sdatestr &"' and '"& edatestr &"'" elseif sdatestr<>"" and edatestr<>"" then sqlstr="select * from viewcompt where AcutalComptDate between '"& sdatestr &"' and '"& edatestr &"'" else sqlstr="select * from viewcompt" end if path=server.mappath("comptpjrpt.rpt") dim dataset1 as dataset=new dataset() dim objcmd as oledbdataadapter=new oledbdataadapter(sqlstr,objcon) objcmd.fill(dataset1,"viewcompt") dim orpt as reportdocument=new reportdocument orpt.load(path) orpt.setdatasource(dataset1) CrystalReportViewer1.ReportSource = orpt end sub ' Define Crystal Reports variables 'Dim crReportDocument As ReportDocument 'Dim crExportOptions As ExportOptions 'Dim crDiskFileDestinationOptions As DiskFileDestinationOptions 'Dim Fname as String ' ??????????? ' ???????? InitializeComponent() ????, ' ???? Button_Click ???,???? ' ??????????????????? sub btnclick(obj as object, e as eventargs) 'crReportDocument = New ReportDocument() ' ????????? ' ????:Chart.rpt 'dim path as string 'path=server.mappath("comptpjrpt.rpt") 'crReportDocument.Load (path) 'Fname = "c:\exports\" & Session.SessionID.ToString & ".pdf" 'crDiskFileDestinationOptions = New DiskFileDestinationOptions() 'CrDiskFileDestinationOptions.DiskFileName = Fname 'crExportOptions = crReportDocument.ExportOptions 'With crExportOptions '.DestinationOptions = crDiskFileDestinationOptions ' .ExportDestinationType = ExportDestinationType.DiskFile ' .ExportFormatType = ExportFormatType.PortableDocFormat 'End With 'crReportDocument.Export() ' ??????? pdf ? ' ?????????? 'Response.ClearContent() 'Response.ClearHeaders() 'Response.ContentType = "application/pdf" 'Response.WriteFile(Fname) 'Response.Flush() 'Response.Close() ' ?????????? 'System.IO.File.Delete(Fname) ExecutaReportFormato() end sub Private Sub ExecutaReportFormato() Dim objCrystalReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument() Dim objCrystalFileDestinationOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions() 'indica o nome do relatório objCrystalReportDocument.Load(Server.MapPath("comptpjrpt.rpt")) 'indica informações de logon Dim crLogonInfo As TableLogOnInfo crLogonInfo = objCrystalReportDocument.Database.Tables(0).LogOnInfo 'crLogonInfo.ConnectionInfo.ServerName = BuscaParam("zhongsb") 'crLogonInfo.ConnectionInfo.UserID = BuscaParam("sa") 'crLogonInfo.ConnectionInfo.Password = BuscaParam("3") crLogonInfo.ConnectionInfo.ServerName = "zhongsb" crLogonInfo.ConnectionInfo.UserID = "sa" crLogonInfo.ConnectionInfo.Password = "3" objCrystalReportDocument.Database.Tables(0).ApplyLogOnInfo(crLogonInfo) 'seta formatação objCrystalReportDocument.FormatEngine.PrintOptions.PaperOrientation = PaperOrientation.Landscape objCrystalReportDocument.FormatEngine.PrintOptions.PaperSize = PaperSize.Paper11x17 ' Seta arquivo de destino do report Dim strExtesion As String ' Select Case drpFormatos.SelectedItem.Text ' Case "PDF" strExtesion = "pdf" objCrystalReportDocument.ExportOptions.ExportFormatType =ExportFormatType.PortableDocFormat ' Case "Excel" ' strExtesion = "xls" ' objCrystalReportDocument.ExportOptions.ExportFormatType = Excel ' Case "Word" ' ' strExtesion = "doc" ' objCrystalReportDocument.ExportOptions.ExportFormatType = WordForWindows ' Case "RTF" 'strExtesion = "rtf" 'objCrystalReportDocument.ExportOptions.ExportFormatType = RichText 'End Select Dim strFile As String = "relat." & strExtesion Dim strPath As String = "c:\inetpub\wwwroot\sampleNet\temp\" Dim strUrl As String = "temp/" 'Response.Write("nome do arquivo: " & strFile) objCrystalFileDestinationOptions.DiskFileName = strPath & strFile 'seta propriedades do relat para export objCrystalReportDocument.ExportOptions.DestinationOptions = objCrystalFileDestinationOptions objCrystalReportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile objCrystalReportDocument.Export() Response.Redirect(strUrl & strFile) End Sub </script> <meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR"> <meta content="Visual Basic 7.0" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:button id="btn1" style="Z-INDEX: 102; LEFT: 3px; POSITION: absolute; TOP: 9px" onclick="btnclick" runat="server" Text="??"></asp:button><CR:CRYSTALREPORTVIEWER id="CrystalReportViewer1" style="Z-INDEX: 101; LEFT: 1px; POSITION: absolute; TOP: 40px" runat="server" DisplayGroupTree="False" Height="50px" Width="350px"></CR:CRYSTALREPORTVIEWER></form> </HTML>
    Friday, September 5, 2003 9:42 PM

All replies

  • User2137666620 posted
    PRB: Crystal Report in Web Application Fails to Log On to SQL Server 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 This article was previously published under Q319264 SYMPTOMS When you use SQL Server 2000 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. STATUS This behavior is by design. MORE INFORMATION Note that this problem does not occur when you use a Microsoft Visual C# .NET or a Microsoft Visual Basic .NET Windows application. To reproduce this problem, you must use a Web application. Steps to Reproduce the Behavior In Microsoft Visual Studio .NET, create a new Microsoft ASP.NET Web application in Microsoft Visual C# .NET. On the File menu, click Add New Item, and then click Add a Crystal Report. Click Using the Report Expert in the dialog box to create your report. Follow the steps in the wizard to set up the connection to your SQL Server database. From the Toolbox, double-click CrystalReportsViewer to add this control to WebForm1.aspx. Right-click WebForm1.aspx in the Solution Explorer window, and then click View Code. In the Page_Load method, add the following code:CrystalReportViewer1.ReportSource = "C:\\Inetpub\\wwwroot\\...\\CrystalReport1.rpt"; where C:\\Inetpub\\wwwroot\\...\\CrystalReport1.rpt is the path to your local copy of the Crystal Report. Verify that the ASPNET account has Read and Write access to your Crystal Report. Compile and run your application. Notice that you receive the error message that is listed in the "Symptoms" section. REFERENCES For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base: 317789 INFO: 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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlmn/html/crsamreportbindingoptionsforwebformsviewers.asp The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products. Last Reviewed: 5/12/2003 Keywords: kbBug kbDebug kbDeployment kbIDEProject kbMaintMode kbprb kbSecurity kbSysAdmin KB319264 kbAudDeveloper
    Saturday, September 6, 2003 12:45 PM
  • User-1572259924 posted
    Please include the solution in VB.net. It is quite frustrating when MS is killing vb.net.
    Friday, November 7, 2003 7:01 PM