Hello,
I am trying to change connection info. of a subreport in crystal reports. In the subreport, I have used two instances of the same table. For example, I have table called tblResource and crystal creates same table instance as tblResource_1. Now, I want to change the connection info of subreport at runtime. In my destination datatabse, there's no instance of tblResource. Please suggest how I can change runtime connection info. The code I am using currently is as follows but it gives error saying : "Failed to open rowset."
============================================================
Dim crossRepDoc As ReportDocument
Dim subRepDoc As New ReportDocument
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crCrossreportObject As CrossTabObject
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crLogOnInfo As TableLogOnInfo
Dim crConnInfo As New ConnectionInfo
Dim crpt205 As r205
crpt205 = New r205
crDatabase = crpt205.Database
crTables = crDatabase.Tables
'Loop through each table in the main report
For Each crTable In crTables
With crConnInfo
.ServerName = "WEBDEV01"
.DatabaseName = "CMS_DB"
.UserID = "sa"
.Password = "a*71584"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
crTable.Location = "CMS_DB.dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
'Set the sections collection with report sections
crSections = crpt205.ReportDefinition.Sections
'Loop through each section and find all the report objects
'logoninfo to the subreport
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind =
ReportObjectKind.SubreportObject Then
'If you find a subreport, typecast the reportobject to a subreport object
crSubreportObject = CType(crReportObject,SubreportObject)
'Open the subreport
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = subRepDoc.Database
crTables = crDatabase.Tables
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo
object then apply the
'logoninfo to the subreport
For Each crTable In crTables
With crConnInfo
.ServerName = "WEBDEV01"
.DatabaseName = "CMS_DB"
.UserID = "sa"
.Password = "a*71584"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
crTable.Location = "CMS_DB.dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
End If
Next
Next
' Set the ReportDocument to the viewer
' The report previews when the form is constructed
CrystalReportViewer1.ReportSource = crpt205
===========================================================
Thanks,
Nidhi
I am trying to change connection info. of a subreport in crystal reports. In the subreport, I have used two instances of the same table. For example, I have table called tblResource and crystal creates same table instance as tblResource_1. Now, I want to change the connection info of subreport at runtime. In my destination datatabse, there's no instance of tblResource. Please suggest how I can change runtime connection info. The code I am using currently is as follows but it gives error saying : "Failed to open rowset."
============================================================
Dim crossRepDoc As ReportDocument
Dim subRepDoc As New ReportDocument
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crCrossreportObject As CrossTabObject
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crLogOnInfo As TableLogOnInfo
Dim crConnInfo As New ConnectionInfo
Dim crpt205 As r205
crpt205 = New r205
crDatabase = crpt205.Database
crTables = crDatabase.Tables
'Loop through each table in the main report
For Each crTable In crTables
With crConnInfo
.ServerName = "WEBDEV01"
.DatabaseName = "CMS_DB"
.UserID = "sa"
.Password = "a*71584"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
crTable.Location = "CMS_DB.dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
'Set the sections collection with report sections
crSections = crpt205.ReportDefinition.Sections
'Loop through each section and find all the report objects
'logoninfo to the subreport
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind =
ReportObjectKind.SubreportObject Then
'If you find a subreport, typecast the reportobject to a subreport object
crSubreportObject = CType(crReportObject,SubreportObject)
'Open the subreport
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = subRepDoc.Database
crTables = crDatabase.Tables
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo
object then apply the
'logoninfo to the subreport
For Each crTable In crTables
With crConnInfo
.ServerName = "WEBDEV01"
.DatabaseName = "CMS_DB"
.UserID = "sa"
.Password = "a*71584"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
crTable.Location = "CMS_DB.dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
End If
Next
Next
' Set the ReportDocument to the viewer
' The report previews when the form is constructed
CrystalReportViewer1.ReportSource = crpt205
===========================================================
Thanks,
Nidhi