Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal report viewer error: invalid report source

Status
Not open for further replies.

harshilpatel

Programmer
Nov 4, 2003
1
0
0
US
Hi All,
I am working on Vb.net application with oracle as my database. I have developed reports using crystal report 9. Usually when you open reports directly in crystal report viewer control it prompts you for any necessary login information. My goal was to provide the login information by means of code, so that the user is not prompted for any login information. I tried to write the following code to achieve that purpose. On running the code I get the error Invalid report source. I know the same code works if I create a report with SQL server as my database. Can you point what might be possibly wrong in my code.

Code:
-----------------------------------------------------------

Dim CrReportDocument As ReportDocument
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As ConnectionInfo

CrReportDocument = New ReportDocument()
CrReportDocument.Load("C:\Report4.rpt")

crConnectionInfo = New ConnectionInfo()

With crConnectionInfo
.DatabaseName = ""
.Password = "xyz"
.ServerName = "xyz"
.UserID = "xyz"
End With

crDatabase = CrReportDocument.Database
crTables = crDatabase.Tables

For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

' crv is crystal report viewer control
crv.ReportSource = CrReportDocument
 
How are you connecting? ODBC, OLEDB, Native?
Don't know if this will help, but...
I am using CR 9 and ODBC. The connection info is different than in CR8. I already have an ODBC connection set up on the computer that has the same name as the "DSN" connection property. The server, database, and other info can be changed in the code.


Dim crxApplication As CRAXDRT.Application
Dim crxTable As CRAXDRT.DatabaseTable
Dim rptAgeing As CRAXDRT.Report
Dim crxProperty As CRAXDRT.ConnectionProperty

mobjReports is a class that contains the information for each connection property.

Set crxApplication = New CRAXDRT.Application
'Open the rpt file needed
Set rptAgeing = crxApplication.OpenReport(App.Path & "\Reports\Criteria.rpt", 1)
For Each crxTable In rptAgeing.Database.Tables
'Set logon info and table location for all tables referenced in the report
Set crxProperty = crxTable.ConnectionProperties("DSN")
crxProperty.Value = mobjReports.DSN
Set crxProperty = crxTable.ConnectionProperties("Database")
crxProperty.Value = mobjReports.Database
Set crxProperty = crxTable.ConnectionProperties("User ID")
crxProperty.Value = mobjReports.UserID
Set crxProperty = crxTable.ConnectionProperties("Password")
crxProperty.Value = mobjReports.Password
crxTable.Location = "Reports.MyApp." & mstrRptTblName
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top