Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Changing Server at Runtime - crystal reports for vb.net

While I am developing my application I am using a SQL server 2005 database on my local machine, my crystal report (version that ships with vb.net 2005) accesses 2 stored procedures that are in the database.

When I run this on another PC (at run time) and point at a different server by changing myConnectionInfo.ServerName = "MyNewServer" I get an error "Procedure sp_mystoredproc expects parameter @Client_ID which was not supplied." As you can see in the code below, it is supplied and works perfectly on my development PC.

The report works using:

myConnectionInfo.ServerName = "MyServer"

But not using

myConnectionInfo.ServerName = "MyOtherServer"

Databases on both servers identical. Code posted below - any ideas?

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()

myConnectionInfo.DatabaseName = "myDatabase"

myConnectionInfo.ServerName = "MyNewServer"

myConnectionInfo.IntegratedSecurity = True

Dim d1 As String

Dim d2 As String

d1 = DateTimePicker1.Value.Date.ToString("dd MMMM yyyy")

d2 = DateTimePicker2.Value.Date.ToString("dd MMMM yyyy")

Dim strReportName As String = "C:\myreport.rpt"

Dim cryRpt As New ReportDocument

cryRpt.Load(strReportName)

SetDBLogonForReport(myConnectionInfo, cryRpt) '**SEE BELOW

Dim crParameterFieldDefinitions As ParameterFieldDefinitions

Dim crParameterFieldDefinition As ParameterFieldDefinition

Dim crParameterValues As New ParameterValues

Dim crParameterDiscreteValue As New ParameterDiscreteValue

crParameterValues.Clear()

crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields

crParameterDiscreteValue.Value = "{" & CurrentClientID(CurrentIndex) & "}"

crParameterFieldDefinition = crParameterFieldDefinitions.Item("@Client_ID")

crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

crParameterDiscreteValue.Value = CurrentBranch(CurrentIndex)

crParameterFieldDefinition = crParameterFieldDefinitions.Item("@Branch_ID")

crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

crParameterDiscreteValue.Value = d1

crParameterFieldDefinition = crParameterFieldDefinitions.Item("@FromDate")

crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

crParameterDiscreteValue.Value = d2

crParameterFieldDefinition = crParameterFieldDefinitions.Item("@ToDate")

crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

crParameterDiscreteValue.Value = CurrentOperatorID

crParameterFieldDefinition = crParameterFieldDefinitions.Item("@User_ID")

crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

CrystalReportViewer1.ReportSource = cryRpt

'**

Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)

Dim myTables As Tables = myReportDocument.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables

Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo

myTableLogonInfo.ConnectionInfo = myConnectionInfo

myTable.Location = myConnectionInfo.DatabaseName & ".dbo." & myTable.Name

myTable.ApplyLogOnInfo(myTableLogonInfo)

Next

End Sub

Edited by: Justine King on Sep 18, 2008 10:07 AM

Not what you were looking for? View more on this topic or Ask a question