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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to set db connection @ runtime

Status
Not open for further replies.

codecomm

Programmer
Feb 14, 2007
121
0
0
US
I'm trying to read a querystring parameter to set my report database location.

I thought the following would work, but if I look in the properties of the report, the database/catalog is set there, and it looks like the code behind below won't create the connection @ runtime. If I try it agains a different database other that what's in the "Properties" when I click on Database/Database Expert and look at the SQL command, I'm prompted with the basic database, username, password page asking for the conneciton properties to what's in "Properties".

Basically, how do I get away from what's in the "Properties" section when I initally create the report?

My codebehind is as follows:

Dim strDB As String = UCase(Request.QueryString("DB"))

crv.ReportSource = "C:\CrystalReports\LCI.rpt"

Dim Counter As Integer

For Counter = 1 To crv.LogOnInfo.Count

With crv.LogOnInfo(Counter - 1).ConnectionInfo

.ServerName = "servername"

.DatabaseName = strDB

.UserID = "UID"

.Password = "pwd"

End With

Next
 
when I try the following I get "Object reference not set to an instance of an object". I got this out of my Crystal book, but it's not working

In my code behind for Page_Load if have only the following:

If Not Page.IsPostBack Then
Dim strDB As String = UCase(Request.QueryString("DB"))
Dim report As New ReportDocument
report.Load("C:\CrystalReports\LCI.rpt")
report.SetDatabaseLogon("uzr","pwd", "server", strDB)
crv.ReportSource = report

End IF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top