dgoncher
asked on
CR XI Report from SQL Stored Procedure
I can't seem to get this report to get the logon info passed. The report is based on a SQL Stored Procedure. My users keep getting the Database login dialog box. It has the Servername, Login ID and Password but the database is blank (and you cannot enter it). I've been trying the suggestions on this website to no avail. The User passed in has dbo rights to the db and rights to execute the stored proc. I've tried it with a sub report and without a sub report. VS2005 CR XI
Here is my function
Friend Function ViewReport(ByVal sReportName As String) As Boolean
'Declaring variables
Dim intCounter As Integer
Dim intCounter1 As Integer
'Crystal Report's report document object
Dim objReport As New _
CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument
'object of table Log on info of Crystal report
Dim ConInfo As New CrystalDecisions.Shared.Ta bleLogOnIn fo
'Sub report object of crystal report.
Dim mySubReportObject As _
CrystalDecisions.CrystalRe ports.Engi ne.Subrepo rtObject
'Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument
Dim index As Integer
Try
'Load the report
objReport.Load(sReportName )
objReport.SetDatabaseLogon ("XXUSER", "USERPWD")
ConInfo.ConnectionInfo.Use rID = "XXUSER"
ConInfo.ConnectionInfo.Pas sword = "USERPWD"
ConInfo.ConnectionInfo.Ser verName = "SqlServer1"
ConInfo.ConnectionInfo.Dat abaseName = "DB109"
' Loop through each section on the report then look
' through each object in the section
' if the object is a subreport, then apply logon info
' on each table of that sub report
For index = 0 To objReport.ReportDefinition .Sections. Count - 1
For intCounter = 0 To _
objReport.ReportDefinition .Sections( index).Rep ortObjects .Count - 1
With objReport.ReportDefinition .Sections( index)
If .ReportObjects(intCounter) .Kind = _
CrystalDecisions.Shared.Re portObject Kind.Subre portObject Then
mySubReportObject = CType(.ReportObjects(intCo unter), _
CrystalDecisions.CrystalRe ports.Engi ne.Subrepo rtObject)
mySubRepDoc = _
mySubReportObject.OpenSubr eport(mySu bReportObj ect.Subrep ortName)
For intCounter1 = 0 To mySubRepDoc.Database.Table s.Count - 1
mySubRepDoc.Database.Table s(intCount er1).Apply LogOnInfo( ConInfo)
' Tried setting twice
' mySubRepDoc.Database.Table s(intCount er1).Apply LogOnInfo( ConInfo)
Next
End If
End With
Next
Next
CrystalReportViewer1.Repor tSource = Nothing
objReport.SetDatabaseLogon ("XXUSER", "USERPWD")
'Set the current report object to report.
CrystalReportViewer1.Repor tSource = objReport
CrystalReportViewer1.Show( )
Return True
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function
Thanks
Here is my function
Friend Function ViewReport(ByVal sReportName As String) As Boolean
'Declaring variables
Dim intCounter As Integer
Dim intCounter1 As Integer
'Crystal Report's report document object
Dim objReport As New _
CrystalDecisions.CrystalRe
'object of table Log on info of Crystal report
Dim ConInfo As New CrystalDecisions.Shared.Ta
'Sub report object of crystal report.
Dim mySubReportObject As _
CrystalDecisions.CrystalRe
'Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalRe
Dim index As Integer
Try
'Load the report
objReport.Load(sReportName
objReport.SetDatabaseLogon
ConInfo.ConnectionInfo.Use
ConInfo.ConnectionInfo.Pas
ConInfo.ConnectionInfo.Ser
ConInfo.ConnectionInfo.Dat
' Loop through each section on the report then look
' through each object in the section
' if the object is a subreport, then apply logon info
' on each table of that sub report
For index = 0 To objReport.ReportDefinition
For intCounter = 0 To _
objReport.ReportDefinition
With objReport.ReportDefinition
If .ReportObjects(intCounter)
CrystalDecisions.Shared.Re
mySubReportObject = CType(.ReportObjects(intCo
CrystalDecisions.CrystalRe
mySubRepDoc = _
mySubReportObject.OpenSubr
For intCounter1 = 0 To mySubRepDoc.Database.Table
mySubRepDoc.Database.Table
' Tried setting twice
' mySubRepDoc.Database.Table
Next
End If
End With
Next
Next
CrystalReportViewer1.Repor
objReport.SetDatabaseLogon
'Set the current report object to report.
CrystalReportViewer1.Repor
CrystalReportViewer1.Show(
Return True
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function
Thanks
ASKER
No
You are applying the connection info to the subreports but not to the main report
ASKER
I added objReport.Database.Tables( intCounter 1).ApplyLo gOnInfo(Co nInfo) but still the same result
ASKER
I did that in a loop (forgot to say that
For intCounter1 = 0 To objReport.Database.Tables. Count - 1
objReport.Database.Tables( intCounter 1).ApplyLo gOnInfo(Co nInfo)
Next
For intCounter1 = 0 To objReport.Database.Tables.
objReport.Database.Tables(
Next
For intCounter1 = 1 To objReport.Database.Tables. Count
Crystal arrays are indexed from 1 so using 0 may cause problems
mlmcc
Crystal arrays are indexed from 1 so using 0 may cause problems
mlmcc
ASKER
objReport.Database.Tables is zero based in my application.
I resolved the issue. Apparently CR is useing the 2005 SQL Native Client. After downloading and installing on eah machine the app works fine.
I resolved the issue. Apparently CR is useing the 2005 SQL Native Client. After downloading and installing on eah machine the app works fine.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for dgoncher's comment http:/Q_27296164.html#36504277
for the following reason:
Issue resolved by myself
Accepted answer: 0 points for dgoncher's comment http:/Q_27296164.html#36504277
for the following reason:
Issue resolved by myself
FYI - I believe the Native client requires a license from MS to be legal.
mlmcc
mlmcc
ASKER
Great, why would crystal require that?
Crystal doesn't. The native client is a MS client. The license is from MS.
Unless they have released a license free version. We started down that path with Crystal 8 and decided we didn't need to buy 5-600 licenses that had to be installed and updated.
mlmcc
Unless they have released a license free version. We started down that path with Crystal 8 and decided we didn't need to buy 5-600 licenses that had to be installed and updated.
mlmcc
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I need to accept the last response as the solution. Mine had flaws
ASKER
Changed the connetion and all is well!
mlmcc