Skip to Content

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

The frustrating "failed to open connection error"

I am working on a project to upgrade about 50 Crystal Reports to a new database.

The Reports are selected and generated by a Visual Studio project.Tables reside on SQL server 2005.

So then, the original prject was written in an older version of VS. I have remapped the tables in the reports - some of the field names have changes, etc...

I have not changed any of the VB code - but when it tries to apply connection info to the subreport tables, I get my error. "Failed to Open the Connection" along with error code -2147482892

My ODBC connection works fine, the reports are able to connect as well while editing or refreshing within the report.

I know there are similar threads, but I have not found one specific enough to this, so I would really appreciate it if someone with more experience than me on this can help me out here getting past this error.

This is the code in question (which worked fine in the old version) - The line where the error is produced, where the connection info is applied to CrTable.Location, is in bold:

Public Sub logonReport(ByRef crReportDoc As ReportDocument, _

ByVal strLogon As strLogonValues)

Dim crSubReportDocument As New ReportDocument

Dim crtableLogonInfos As New TableLogOnInfos

Dim crtableLogonInfo As New TableLogOnInfo

Dim crConnectionInfo As New ConnectionInfo

Dim Crtables As Tables

Dim Crtable As Table

Dim crSections As Sections

Dim crSection As Section

Dim crRptObjects As ReportObjects

Dim crRptObject As ReportObject

Dim crSubRptObject As SubreportObject

With crConnectionInfo

.ServerName = strLogon.sServer

.DatabaseName = strLogon.sDatabase

.UserID = strLogon.sUserID

.Password = strLogon.sPassword

End With

Crtables = crReportDoc.Database.Tables

'Loop through all tables in the report and apply the connection

'information for each table.

For Each Crtable In Crtables

crtableLogonInfo = Crtable.LogOnInfo

crtableLogonInfo.ConnectionInfo = crConnectionInfo

Crtable.ApplyLogOnInfo(crtableLogonInfo)

Next

crSections = crReportDoc.ReportDefinition.Sections

For Each crSection In crSections

crRptObjects = crSection.ReportObjects

' Loop through objects to find any subreports

For Each crRptObject In crRptObjects

If crRptObject.Kind = ReportObjectKind.SubreportObject Then

crSubRptObject = CType(crRptObject, SubreportObject)

crSubReportDocument = crSubRptObject.OpenSubreport(crSubRptObject.SubreportName)

' Use logon info to log onto any tables within subreports

Crtables = crSubReportDocument.Database.Tables

For Each Crtable In Crtables

crtableLogonInfo = Crtable.LogOnInfo

crtableLogonInfo.ConnectionInfo = crConnectionInfo

Crtable.ApplyLogOnInfo(crtableLogonInfo)

Crtable.Location = crConnectionInfo.DatabaseName + "." + crConnectionInfo.UserID + "." + Crtable.Name

pProgress.Increment(2)

Next

End If

Next

Next

End Sub

Edited by: RoddyPiper on Apr 15, 2009 12:00 AM

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