Saturday, July 3, 2010

Crystal Reports Windows Application - Failed to open the connection

Failed to open the connection.
Details: [Database Vendor Code: 4060 ]
Failed to open the connection.
temp_62a7065e-b077-44f0-8593-7dca04303f6a {7498BCDB-812A-4D53-B04E-9BD3E45EC6B6}.rpt
Details: [Database Vendor Code: 4060 ]
Stack Trace:
at CrystalDecisions.ReportAppServer.Controllers.RowsetControllerClass.CreateCursor(ISCRGroupPath GroupPath, RowsetMetaData MetaData, Int32 Reserved)
at CrystalDecisions.ReportAppServer.CrystalReportDataView.EnsureDataTableIsFilled()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_DataView()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_InternalCollection()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_Count()


OK, the error above appeared out of no where and we had to spend hours and hours to figure out what is going on.

Let's get some info about the environment.

Dev database - where developers write code against and is used to design new reports.

QA database - where qa staff run the test cases in the app against.

Both databases are on the same server.

-Code sequence before issue
1.Change ReportDocument TableLogOnInfo using the app connection string.
2.Then load Report Viewer

Our requirement changed and wants to display report viewer if there are any records.
--Code sequence after issue happened
1.Check ReportDocument Rows Count and display message saying no records, and skip step2 and 3.
2.Change ReportDocument TableLogOnInfo using the app connection string.
3.Then load Report Viewer.

Problem here is step1 where row count is checked, when the check is done data is fetched from the database to which report is pointed at the design time as the connection is not updated until step2.

When QA staff runs the report at step1 database context changes to dev database where QA staff has no access to the data, for that matter they dont even have a login in the database which is why "Failed to open the connection." error is given.

GIST HERE IS UPDATE THE TABLELOGONINFO FOR REPORTS and SUBREPORTS WITH THE APPLiCATION INSTANCE CONNECTION STRING BEFORE QUERYING THE ROW COUNT ON THE REPORT DOCUMENT.

--SAMPLE CODE TO CHANGE THE CONNECTION INFO
Dim LogonInfo As New TableLogOnInfo

'-- Set the connection info
LogonInfo.ConnectionInfo.ServerName = GetServerName(connectionString)
LogonInfo.ConnectionInfo.DatabaseName = GetDatabaseName(connectionString)
If UsesIntegratedSecurity(connectionString) Then
LogonInfo.ConnectionInfo.IntegratedSecurity = True
Else
LogonInfo.ConnectionInfo.UserID = GetUserName(connectionString)
LogonInfo.ConnectionInfo.Password = GetUserPassword(connectionString)
End If

'--- Apply the connection info to each database table
For Each Table As Table In report.Database.Tables
Table.ApplyLogOnInfo(LogonInfo)
Next

'--- Also set connection info in the subreports
For Each subReport As ReportDocument In report.Subreports
For Each Table As Table In subReport.Database.Tables
Table.ApplyLogOnInfo(LogonInfo)
Next
Next

No comments:

Post a Comment

IIS Manager Crashes on Load/Start Windows 7, IIS 7.5

IIS Manager Crashes on Start  Windows 7, IIS 7.5, Power Shell 5.1. Here is the error I got in the event viewer. IISMANAGER_CRASH IIS Ma...