Crystal Report lossing parameters info
I am having an issue with CR regarding the db connection and its parameter. I have a code below that changes database based on values passed and set parameters for the report, if neccesary. The code works in my local machine, when I run it everything seems to work. When I move it to a different machine the same code does not work. The reports that do not require parameters run however for those requiring parameters failed with the error "Invalid field name". I tried different combination to see if there was something I was stting up incorrectly. I was able to debug this code from the computer having the issue. I check the parameters in the report using rptdocument.DataDefinition.ParameterFields.count and I can see that the ParameterFields collection is reset to 0 right after I execute the line rptDocument.Database.Tables(0).location = tName. That does not happend in my local pc, why it does not retain the information about the parameters after I set to new location?
I am not sure why this behavior, In my local pc this code works fine but moving it to another server the code behaves this way.
Any suggestion will be appreciated (I have been dealing with this for 3 days now)
*** this is the code ***
Public Overloads Sub runReport(ByVal reportName As String, _
ByVal parameters As ArrayList)
'connection variables
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crLogOnInfo As New TableLogOnInfo
Dim crConnInfo As New ConnectionInfo
Dim p As System.Web.UI.Page = New System.Web.UI.Page
Dim serverutil As HttpServerUtility = p.Server
' this code if for changing connection on the fly. not working as expected
Try
rptDocument.Load(serverutil.MapPath(rptPath & reportName))
With crConnInfo
.ServerName = _
ConfigurationSettings.AppSettings.Item("RptServerN ame")
.DatabaseName = _
ConfigurationSettings.AppSettings.Item("RptDatabas eName")
.UserID = _
ConfigurationSettings.AppSettings.Item("RptUser")
.Password = _
ConfigurationSettings.AppSettings.Item("RptPass")
End With
crLogOnInfo.ConnectionInfo = crConnInfo
Dim tName As String = rptDocument.Database.Tables(0).Name
Dim tLocation = crConnInfo.DatabaseName & ".dbo." & tName
crTable = rptDocument.Database.Tables(0)
crTable.ApplyLogOnInfo(crLogOnInfo)
rptDocument.Database.Tables(0).Location = tName 'tLocation
' set parameters, if any
If Not parameters Is Nothing Then
'set parameters
For Each el As CommonObject In parameters
rptDocument.SetParameterValue(el.Id, el.Description)
Next
End If
Dim s As System.IO.MemoryStream = _
rptDocument.ExportToStream(ExportFormatType.Portab leDocFormat)
' to the browser instead of creating files on disk.
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=Report.pdf")
.BinaryWrite(s.ToArray)
.Flush()
.End()
End With
Catch ex As Exception
Throw New AppException(ex.Message)
End Try
End Sub
|