on 12-12-2020 10:56 PM
Dim RptDoc = New ReportDocument
Dim exOpt As ExportOptions
Dim dfdopt = New DiskFileDestinationOptions
RptDoc.Load(Server.MapPath("~/InvoiceWithPayments.rpt"))
dfdopt.DiskFileName = Server.MapPath("~/Invoice" & Invoice & ".pdf")
exOpt = RptDoc.ExportOptions
exOpt.ExportDestinationType = ExportDestinationType.DiskFile
exOpt.ExportFormatType = ExportFormatType.PortableDocFormat
exOpt.DestinationOptions = dfdopt
RptDoc.SetParameterValue("InvoiceNumber", CObj(14161))
RptDoc.Export()
I am facing following error in running the above code
[NullReferenceException: Object reference not set to an instance of an object.]
CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +645
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) +208
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export() +68
CrystalDecisions.CrystalReports.Engine.ReportDocument.Export() +58
ASP.cr2pdf_aspx.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in C:\Customers\CR2PDF.aspx:76
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +9737744
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +13
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1303
Remember. Report file have all credential saved to connect. This code works well on Win8 and Win2012 Server but don't work another instance of Win2012 Server.
Thanks
Use Fiddler and compare the info.
It should also show you what is missing or does not have permissions to.
Has Records = True just means it's a report with saved data, it does not and never has saved the password in any version of CR Reports. That would be a huge security hole...
If no issue with 64 bit that means you have the 64 bit Client installed and configured, not working in 32 bit means you don't have the 32 bit Client install and/or it's not configure and/or not working.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I checked your code:
RptDoc.Load(Server.MapPath("~/InvoiceWithPayments.rpt"))
dfdopt.DiskFileName = Server.MapPath("~/Invoice" & Invoice & ".pdf")
exOpt = RptDoc.ExportOptions
exOpt.ExportDestinationType = ExportDestinationType.DiskFile
exOpt.ExportFormatType = ExportFormatType.PortableDocFormat
exOpt.DestinationOptions = dfdopt
RptDoc.SetParameterValue("InvoiceNumber", CObj(14161))
// insert log on code here and search for subreports, if any they need to be
// logged on also.
You are not setting the log on info, just the parameter, if you are setting it somewhere else then it's BEFORE the parameter set.
CR does not save the password in the RPT file so unless you are using Trusted Auth it's likely failing to log on.
And you never indicated what line of code it's throwing the exception on?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply!
All the information to connect to mssql is saved in the rpt file. If you look the details of
Object {CrystalDecisions.CrystalReports.Engine.ReportDocument} Detail
you will note HasRecords.
HasRecords: True
There was Login issue when i have complied app for 32bit
I have used following two codes to remove it. But there is no login issue when App is 64bit
RptDoc.SetDatabaseLogon("USER", "PASSWORD", "SERVER1231", "DB")
and Dim myConnectionInfo = New ConnectionInfo
myConnectionInfo.UserID = "USER"
myConnectionInfo.Password = "PASSWORD"
myConnectionInfo.ServerName = "SERVER1231"
myConnectionInfo.DatabaseName = "DB"
Dim myTables As Tables = RptDoc.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
For security i have changed the login credentials.Thanks Again
Set parameter first before exporting.
Does it export to any other format?
Error still means the report object is out of scope.
Try hard coding the path to the folder:
dfdopt.DiskFileName = "c:\Invoice.pdf"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Set parameter first before exporting.
Please check code on my first post. Everything is done before exporting.
> Does it export to any other format?
No
> Error still means the report object is out of scope.
As i already explained to you. Please read the error in details. Here are properties of ReportDocument object after error appear.
Object{CrystalDecisions.CrystalReports.Engine.ReportDocument}Detail
LogLicensingExceptions: False
ReportSource: CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass
Subreports: CrystalDecisions.CrystalReports.Engine.Subreports
Database: CrystalDecisions.CrystalReports.Engine.Database
DataDefinition: CrystalDecisions.CrystalReports.Engine.DataDefinition
ExportOptions: CrystalDecisions.Shared.ExportOptions
FilePath:C:\Customers\invoices\ExportedBranding Invoice With PaymentswithParameter2.rpt
FormatEngine: CrystalDecisions.CrystalReports.Engine.FormatEngine
HasSavedData: False
IsLoaded: True
IsSubreport: False
HasRecords: True
Name:
PrintOptions: CrystalDecisions.CrystalReports.Engine.PrintOptions
RecordSelectionFormula:(({tblInvoices.Status}="Posted" AND {tblInvoices.InvoiceNumber} = {?InvoiceNumber} ) AND {tvwr_Invoices.InvoiceNumber} = {?InvoiceNumber} )
ReportDefinition: CrystalDecisions.CrystalReports.Engine.ReportDefinition
ReportOptions: CrystalDecisions.CrystalReports.Engine.ReportOptions
SummaryInfo: CrystalDecisions.CrystalReports.Engine.SummaryInfo
HistoryInfos: CrystalDecisions.CrystalReports.Engine.HistoryInfos
SavedXmlExportFormats: CrystalDecisions.CrystalReports.Engine.XmlExportFormats
DefaultXmlExportSelection:0
DataSourceConnections: CrystalDecisions.CrystalReports.Engine.InternalDataSourceConnections
ParameterFields: CrystalDecisions.Shared.ParameterFields
ReportClientDocument: CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper
FileName: rassdk://C:\Customers\invoices\ExportedBranding Invoice With PaymentswithParameter2.rpt
IsRPTR: False
ReportAppServer:
UriIsUserEditable: True
Container:System.NullReferenceException:Objectreferencenotsetto an instanceof an object.
Site:System.NullReferenceException:Objectreferencenotsetto an instanceof an object.Rows:
ReportRequestStatus: CrystalDecisions.CrystalReports.Engine.ReportRequestStatus
> Try hard coding the path to the folder:
No working with it.
That error ALWAYS means the report object is null when doing something in your code.
Single step through it check the report object is anything but null...
Your code sets the parameter but never logs onto the DB.
If your data source is a Stored Procedure you need to set the parameter before the log on code.
Make sure the WEB Server ahs permissions to write to that folder also.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply!
There is no error in following statements
Dim RptDoc = New ReportDocument
RptDoc.Load(Server.MapPath("~/InvoiceWithPayments.rpt"))
exOpt = RptDoc.ExportOptions
RptDoc.SetParameterValue("InvoiceNumber", CObj(14161))<br>
3 times Using Report Object after declaring have no error.
The error appear in the following statement
RptDoc.Export(exOpt)
Remember RptDoc is not null or nothing at this point, but an internal call to CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)Please check the code again!
There is no issue of permissions and database login (these are fixed)
Remember: Same code is running perfectly on Windows 8.1 and Windows 2012 Server, but not working on another instance of Windows 2012 Server.
Thanks
Try changing the .export call to this:
RptDoc.Export(exOpt);
Looking at the help file, the call to export needs to have the export options passed in as a parameter.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply!
Results are exactly same check it here http://customers.mltigerpaw.com/CR2PDF.aspx
here is the detailed information of RptDoc after error appear. It may be helpful to diagnose issue.
Object {CrystalDecisions.CrystalReports.Engine.ReportDocument} Detail
LogLicensingExceptions: False
ReportSource: CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass
Subreports: CrystalDecisions.CrystalReports.Engine.Subreports
Database: CrystalDecisions.CrystalReports.Engine.Database
DataDefinition: CrystalDecisions.CrystalReports.Engine.DataDefinition
ExportOptions: CrystalDecisions.Shared.ExportOptions
FilePath: C:\Customers\invoices\ExportedBranding Invoice With PaymentswithParameter2.rpt
FormatEngine: CrystalDecisions.CrystalReports.Engine.FormatEngine
HasSavedData: False
IsLoaded: True
IsSubreport: False
HasRecords: True
Name:
PrintOptions: CrystalDecisions.CrystalReports.Engine.PrintOptions
RecordSelectionFormula: ( ( {tblInvoices.Status} = "Posted" AND {tblInvoices.InvoiceNumber} = {?InvoiceNumber} ) AND {tvwr_Invoices.InvoiceNumber} = {?InvoiceNumber} )
ReportDefinition: CrystalDecisions.CrystalReports.Engine.ReportDefinition
ReportOptions: CrystalDecisions.CrystalReports.Engine.ReportOptions
SummaryInfo: CrystalDecisions.CrystalReports.Engine.SummaryInfo
HistoryInfos: CrystalDecisions.CrystalReports.Engine.HistoryInfos
SavedXmlExportFormats: CrystalDecisions.CrystalReports.Engine.XmlExportFormats
DefaultXmlExportSelection: 0
DataSourceConnections: CrystalDecisions.CrystalReports.Engine.InternalDataSourceConnections
ParameterFields: CrystalDecisions.Shared.ParameterFields
ReportClientDocument: CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper
FileName: rassdk://C:\Customers\invoices\ExportedBranding Invoice With PaymentswithParameter2.rpt
IsRPTR: False
ReportAppServer:
UriIsUserEditable: True
Container: System.NullReferenceException: Object reference not set to an instance of an object.
Site: System.NullReferenceException: Object reference not set to an instance of an object.
Rows:
ReportRequestStatus: CrystalDecisions.CrystalReports.Engine.ReportRequestStatus
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.