Crytal Reports...Export Error with parms

T

Tim Jones

Hey all,

I am trying to try get a crytal report running properly. A "Hello World"
report that does not add criteria to the record selection formula of the
report (either in the development tool, or in the code) works fine.

However, when I try to add any parameter through the record selection
formula and/or the report parameters method, the report crashes.

I have tried each of the methods:

1. Use the Record Selection Formula property:

crReportDocument.DataDefinition.RecordSelectionFormula = "{qryTest.ID} =
54"

2. Use the Crystal Parameters collection(s)

crParameterFieldDefinitions =
crReportDocument.DataDefinition.ParameterFields

crParameterFieldDefinition = crParameterFieldDefinitions.Item("[@TestID]")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New
CrystalDecisions.Shared.ParameterDiscreteValue()

crParameterDiscreteValue.Value = 54
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


Both of the methods above work fine on my development machine but the
testing server gives these errors.

I also set the record selection formula in the report to automatically set
the TestID parameter = 54 and then tested that report on the testing server
and everything worked.

So the issue seems to be with populating the crystal report's parameters at
runtime. The error that comes back with a logon failure at the .Export
line.

I have tried two methods to logon to the reports:
####################
Basic:
With tliTableLogonInfo.ConnectionInfo
.ServerName = m_strDSNName
.DatabaseName = m_strDatabase
.UserID = m_strUserId
.Password = m_strPassword
End With

'setup each connection in the report
For Each tTable In crReportDocument.Database.Tables
tTable.ApplyLogOnInfo(tliTableLogonInfo)
Next tTable
####################
and Complex (loops through sub-reports):
Dim mySection As Section
Dim mySections As Sections
Dim myReportObject As ReportObject
Dim myReportObjects As ReportObjects
Dim mySubReportObject As SubreportObject
Dim mySubRepDoc As New ReportDocument()

'Declare all of the sections of the main report
mySections = crReportDocument.ReportDefinition.Sections

'Loop through the sections in the main report to find the subreport objects
'then set the logon information to the subreport
Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

For Each mySection In mySections
myReportObjects = mySection.ReportObjects

For Each myReportObject In myReportObjects
If myReportObject.Kind = ReportObjectKind.SubreportObject Then
'Subreport Found - convert the report object to a sub report type
mySubReportObject = CType(myReportObject, SubreportObject)
'Set the specific instance of this subreport
mySubRepDoc = mySubReportObject.OpenSubreport
(mySubReportObject.SubreportName)

'Set the login information for the current subreport(found)
For Each crTable In mySubRepDoc.Database.Tables
myLogin = crTable.LogOnInfo
myLogin.ConnectionInfo.ServerName = m_strDSNName
myLogin.ConnectionInfo.DatabaseName = m_strDatabase
myLogin.ConnectionInfo.UserID = m_strUserId
myLogin.ConnectionInfo.Password = m_strPassword
crTable.ApplyLogOnInfo(myLogin)
Next
End If
Next
Next
####################
Does anyone know of other methods to filter a report at runtime? Or is
there a Crystal DLL that I need to move from my dev machine to the server
to allow for the record selection properties to be set at runtime?

OR ANY OTHER INFO WOULD BE GREAT!!!

Thanks,

TJ
 
J

Jerry Boone

This is working code... In the report design, the parameter name is @pBDate
and is a DateTime type. In the Select Expert, I use.... is equal to and
the value is {?@pBDate} which takes the passed parameter to the cr query
renderer.

If you encounter login problems, let me know - I have some gotcha's that
remedy that.


Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

'public class....
'inherits....

'Web Form Designer....

Dim cdoc As ReportDocument

Private Sub Page_Load...

'load cr object...
cdoc = New CrystalReport1

'...or you can also do this...
'crDoc.Load("C:\reports\CrystalReport1.rpt")

Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As ConnectionInfo

crConnectionInfo = New ConnectionInfo
With crConnectionInfo
.ServerName = "sqlServer"
.DatabaseName = "sqlDatabase"
.UserID = "sqlLogin"
.Password = "password"
End With

crDatabase = cdoc.Database
crTables = crDatabase.Tables

For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

Dim crPFDs As ParameterFieldDefinitions
Dim crPFD As ParameterFieldDefinition

Dim crParameterValues As New ParameterValues
Dim crPBdate As New ParameterDiscreteValue

crPFDs = cdoc.DataDefinition.ParameterFields
crPBdate.Value = "11/28/03"
crPFD = crPFDs.Item("@pBDate")
crParameterValues = crPFD.CurrentValues
crParameterValues.Add(crPBdate)
crPFD.ApplyCurrentValues(crParameterValues)

Me.CrystalReportViewer1.ReportSource = cdoc

End Sub



--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz



Tim Jones said:
Hey all,

I am trying to try get a crytal report running properly. A "Hello World"
report that does not add criteria to the record selection formula of the
report (either in the development tool, or in the code) works fine.

However, when I try to add any parameter through the record selection
formula and/or the report parameters method, the report crashes.

I have tried each of the methods:

1. Use the Record Selection Formula property:

crReportDocument.DataDefinition.RecordSelectionFormula = "{qryTest.ID} =
54"

2. Use the Crystal Parameters collection(s)

crParameterFieldDefinitions =
crReportDocument.DataDefinition.ParameterFields

crParameterFieldDefinition = crParameterFieldDefinitions.Item("[@TestID]")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New
CrystalDecisions.Shared.ParameterDiscreteValue()

crParameterDiscreteValue.Value = 54
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


Both of the methods above work fine on my development machine but the
testing server gives these errors.

I also set the record selection formula in the report to automatically set
the TestID parameter = 54 and then tested that report on the testing server
and everything worked.

So the issue seems to be with populating the crystal report's parameters at
runtime. The error that comes back with a logon failure at the .Export
line.

I have tried two methods to logon to the reports:
####################
Basic:
With tliTableLogonInfo.ConnectionInfo
.ServerName = m_strDSNName
.DatabaseName = m_strDatabase
.UserID = m_strUserId
.Password = m_strPassword
End With

'setup each connection in the report
For Each tTable In crReportDocument.Database.Tables
tTable.ApplyLogOnInfo(tliTableLogonInfo)
Next tTable
####################
and Complex (loops through sub-reports):
Dim mySection As Section
Dim mySections As Sections
Dim myReportObject As ReportObject
Dim myReportObjects As ReportObjects
Dim mySubReportObject As SubreportObject
Dim mySubRepDoc As New ReportDocument()

'Declare all of the sections of the main report
mySections = crReportDocument.ReportDefinition.Sections

'Loop through the sections in the main report to find the subreport objects
'then set the logon information to the subreport
Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo

For Each mySection In mySections
myReportObjects = mySection.ReportObjects

For Each myReportObject In myReportObjects
If myReportObject.Kind = ReportObjectKind.SubreportObject Then
'Subreport Found - convert the report object to a sub report type
mySubReportObject = CType(myReportObject, SubreportObject)
'Set the specific instance of this subreport
mySubRepDoc = mySubReportObject.OpenSubreport
(mySubReportObject.SubreportName)

'Set the login information for the current subreport(found)
For Each crTable In mySubRepDoc.Database.Tables
myLogin = crTable.LogOnInfo
myLogin.ConnectionInfo.ServerName = m_strDSNName
myLogin.ConnectionInfo.DatabaseName = m_strDatabase
myLogin.ConnectionInfo.UserID = m_strUserId
myLogin.ConnectionInfo.Password = m_strPassword
crTable.ApplyLogOnInfo(myLogin)
Next
End If
Next
Next
####################
Does anyone know of other methods to filter a report at runtime? Or is
there a Crystal DLL that I need to move from my dev machine to the server
to allow for the record selection properties to be set at runtime?

OR ANY OTHER INFO WOULD BE GREAT!!!

Thanks,

TJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top