If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I have a VS 2008 app I am building. I REALLY need your help VB Crystal Reports Experts! Works great but asks for database credentials when Crystal Reports Viewer attempts to launch the report. The stucture is that the app passes parameters to a stored procedure on a MS SQL box which creates a temporary table. Then the CR inside of the CRviewer reports on the temporary table. All works fine except that the user is prompted for DB credentials (information they are not allowed to know), when the CRviewer launches. I have been struggling with this for a week! I have searched and searched the code here and everywhere else but I cannot find something that works or if I do find something, I am affraid to try it because I don't know where it should go? I think maybe it needs to be part of this but I don't know if this is where it belongs or what the code should be.

'If you are using a Strongly Typed report (Imported in your project) named CrystalReport1.rpt use the following:

Code:

Dim crReportDocument As New CrystalReport1()

'If you are using a Non-Typed report, and loading a report outside of the project, use the following:

Code:

Dim crReportDocument As New ReportDocument()
crReportDocument.Load("c:\myReports\myReport.rpt")

'Set the ConnectionInfo properties for logging on to the Database

'If you are using ODBC, this should be the DSN name NOT the physical server name.
'If you are NOT using ODBC, this should be the physical server name

Code:

With crConnectionInfo
.ServerName = "DSN or Server Name"
'If you are connecting to Oracle there is no DatabaseName. Use an empty string. For example, .DatabaseName = ""
.DatabaseName = "DatabaseName"
.UserID = "Your User ID"
.Password = "Your Password"
End With

'This code works for both user tables and stored procedures.
'Set the CrTables to the Tables collection of the report

Code:

CrTables = crReportDocument.Database.Tables
'Loop through each table in the report and apply the LogonInfo information
For Each CrTable in CrTables
CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
'If your DatabaseName is changing at runtime, specify the table location.
'For example, when you are reporting off of a Northwind database on SQL server you should have the following line of code:
crTable.Location = "Northwind.dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
'Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument

JG

... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Thank you for your reply. I have seen this before and attempted to use it. I failed. I don't know if I was even attempting correctly because to begin I do not know where this code should go. Does it go into the code for the CR viewer page? Does it go into the code for the main application that is launching the CR viewer? Does the fact that my CR is run off of a temporary table which is created by the main application and then reported upon by the CR change the situation? This works correctly. I have all the parameters passing to the SP and all the data is coming into the the temp table in the tempdb. But when the CR viewer is launched as another form from the main application; it asks for the database credentials at this time. Everything I have done to attempt to embed these credentials has either not changed the situation and all runs the same. Or it causes the report to come up blank even though the data is all in the table when I look at the table in MS SQL. I would love it if you could tell me where to put the code and if you see any basic flaws in what I am doing. Sorry for being such a newbie. I am learning quick! Thanks.