By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

Crytal Reports...Export Error with parms

P: n/a
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.RecordSelectionFor mula = "{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(crPa rameterValues)
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <ti**********@yahoo.ca> wrote in message
news:Xn*********************************@24.70.95. 211...
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.RecordSelectionFor mula = "{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(crPa rameterValues)
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.