03-02-2024 11:28 AM - edited 03-11-2024 4:27 AM
I have installed crystal reports 2011 for .net 4.0. I create crystal report using visual studio. I use command to get data. the command gets data from 2 database. the 2nd database has same user and password as the one provide during creating command. only name and content of 2nd database is different. name of the 2nd database is passed as parameter to the command.
Everything works fine. but when i change the database connection settings from backend the reports give error [
Error in File temp_7eda6175-1a02-42ab-b517-bfef5dc33ba6 10524_3948_{C8BE61CE-D420-4BBB-8BFD-67B238688671}.rpt:
Failed to retrieve data from the database.
Details: [Database Vendor Code: 207 ]
]
but when i manually verify database, and run the project the report works again.
my problem is i need to run this report on different client system. each time in each machine i cant verify database manually.
I tried crystalreportobject.verifydatabase(). but that results in an exception
[log on failed]
login credentials are correct. i have double checked
please help
Code used to set the database connection at runtime
part1
With crConnectionInfo
.AllowCustomConnection = True
.IntegratedSecurity = False
.ServerName ="Server"
.DatabaseName = "Database"
.UserID = "User"
.Password ="password"
End With
CrTables = objcrRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crConnectionInfo.Type = crtableLogoninfo.ConnectionInfo.Type
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
part 2
Dim crSections As CrystalDecisions.CrystalReports.Engine.Sections
Dim crReportObjects As ReportObjects
Dim crSubreportObject As SubreportObject
Dim crSubreportDocument As ReportDocument
Dim crDatabase As Database
Dim tableIndex As Integer
Dim CrTables1 As Tables
crSections = objdayendRpt.ReportDefinition.Sections
For Each crSection As CrystalDecisions.CrystalReports.Engine.Section In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)
Dim mysubname As String = crSubreportObject.SubreportName.ToString()
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = crSubreportDocument.Database
CrTables1 = crDatabase.Tables
tableIndex = 0
For Each crTable1 As CrystalDecisions.CrystalReports.Engine.Table In CrTables1
Dim TableName As String = crTable1.Name.ToString()
tableIndex += 1
crtableLogoninfo = crTable1.LogOnInfo
crConnectionInfo.Type = crtableLogoninfo.ConnectionInfo.Type
crtableLogoninfo.ConnectionInfo = crConnectionInfo
crTable1.ApplyLogOnInfo(crtableLogoninfo)
Next
crSubreportDocument.SetDatabaseLogon("User","Password", "Server", "Database")
End If
Next
Next
Hello,
Go here:
https://help.sap.com/docs/SUPPORT_CONTENT/crystalreports/3354091173.html
On that page I added 2 test applications, one for setting log on a Parameters and the other for printing:
how-to-parameters-in-crystal-reports-for-visual-studio-net
Printing Crystal Reports in .NET
The Parameter test app has options to set the log on info for the main report and each subreport, you must do this because subreports is there for using a second data source.
Your issue could be in your use of the Command object, if your multiple data sources is linked in the Command this is not the way you do it, you must use a subreport per each DB connection and link the subreports to the main report.
Also, download SP 35, it's the latest versions, CR for VS is only supported with the latest version, see my blog on how to upgrade also:
Also, CR follow DB security, if the user you are logged in as doesn't have permissions to access the data for the report it will give you a log on error., not sure what error 207 is for your DB.
See if that helpos
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
part1
With crConnectionInfo
.AllowCustomConnection = True
.IntegratedSecurity = False
.ServerName ="Server"
.DatabaseName = "Database"
.UserID = "User"
.Password ="password"
End With
CrTables = objcrRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crConnectionInfo.Type = crtableLogoninfo.ConnectionInfo.Type
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
part 2
Dim crSections As CrystalDecisions.CrystalReports.Engine.Sections
Dim crReportObjects As ReportObjects
Dim crSubreportObject As SubreportObject
Dim crSubreportDocument As ReportDocument
Dim crDatabase As Database
Dim tableIndex As Integer
Dim CrTables1 As Tables
crSections = objdayendRpt.ReportDefinition.Sections
For Each crSection As CrystalDecisions.CrystalReports.Engine.Section In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)
Dim mysubname As String = crSubreportObject.SubreportName.ToString()
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = crSubreportDocument.Database
CrTables1 = crDatabase.Tables
tableIndex = 0
For Each crTable1 As CrystalDecisions.CrystalReports.Engine.Table In CrTables1
Dim TableName As String = crTable1.Name.ToString()
tableIndex += 1
crtableLogoninfo = crTable1.LogOnInfo
crConnectionInfo.Type = crtableLogoninfo.ConnectionInfo.Type
crtableLogoninfo.ConnectionInfo = crConnectionInfo
crTable1.ApplyLogOnInfo(crtableLogoninfo)
Next
crSubreportDocument.SetDatabaseLogon("User","Password", "Server", "Database")
End If
Next
Next
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.