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

Passing datasource name as a parameter when opening a report from ASP

Status
Not open for further replies.

menazbk

Programmer
Dec 24, 2001
6
EG
I use the CRViewer activeX to open reports from ASP and VBScript:

Dim webBroker, webSource
Set webBroker = CreateObject("WebReportBroker.WebReportBroker")
Set webSource = CreateObject("WebReportSource.WebReportSource")

webSource.ReportSource = webBroker
webSource.URL = "ReportName.rpt?user0=UserName&password0=Password"
webSource.PromptOnRefresh = False
CRViewer.ReportSource = webSource
CRViewer.ViewReport

I would like to pass the datasource name as a prameter in the URL string.
Is it possible? If yes, how?

Thanks in advance
 
Hi menazbk.
Please check my hint with subject "Hints For Dynamic Database".I am sure it will help you.If you have questions to ask let me know
 
Thank you Hattusas.

I used the following code in a file names rptserver.asp:


If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("Crystal.CRPE.Application")
End If

If IsObject(session("oRpt")) Then
Set session("oRpt") = Nothing
End If

Path = "Physical Path & Report Name.rpt"

Set session("oRpt") = session("oApp").OpenReport(Path, 1)

'Database User And Password
userid = "my user id"
password = "my password"

' Set the location
set crtable = session("oRpt").Database.Tables.Item(1)
crtable.SetLogonInfo "DSN", "", cstr(userid), cstr(password)

session("oRpt").DiscardSavedData

On Error Resume Next

session("oRpt").ReadRecords

If Err.Number <> 0 Then
Response.Write &quot;An Error has occured on the server in attempting to access the data source &quot; & Session(&quot;i&quot;)
Else

If IsObject(session(&quot;oPageEngine&quot;))Then
set session(&quot;oPageEngine&quot;) = nothing
End If
Set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine
End If


Then I used the following code in a file names ViewReport.asp:


<HTML>
<HEAD>
<TITLE>Seagate ActiveX Viewer</TITLE>
</HEAD>
<BODY BGCOLOR=C6C6C6 LANGUAGE=VBScript ONLOAD=&quot;Page_Initialize&quot;>

<OBJECT ID=&quot;CRViewer&quot;
CLASSID=&quot;CLSID:C4847596-972C-11D0-9567-00A0C9273C2A&quot;
WIDTH=100% HEIGHT=95%
CODEBASE=&quot;/viewer/activeXViewer/activexviewer.cab#Version=8,0,0,224&quot;>
<PARAM NAME=&quot;EnableRefreshButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableGroupTree&quot; VALUE=0>
<PARAM NAME=&quot;DisplayGroupTree&quot; VALUE=0>
<PARAM NAME=&quot;EnablePrintButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableExportButton&quot; VALUE=1>
<PARAM NAME=&quot;EnableDrillDown&quot; VALUE=1>
<PARAM NAME=&quot;EnableSearchControl&quot; VALUE=1>
<PARAM NAME=&quot;EnableAnimationControl&quot; VALUE=1>
<PARAM NAME=&quot;EnableZoomControl&quot; VALUE=1>
<PARAM NAME=&quot;DisplayBorder&quot; VALUE=1>
<PARAM NAME=&quot;EnableProgressControl&quot; VALUE=1>

</OBJECT>

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub Page_Initialize
On Error Resume Next

Dim webBroker
Set webBroker = CreateObject(&quot;WebReportBroker.WebReportBroker&quot;)
Dim webSource
Set webSource = CreateObject(&quot;WebReportSource.WebReportSource&quot;)

webSource.ReportSource = webBroker
webSource.URL = &quot;rptserver.asp&quot;

webSource.PromptOnRefresh = False
CRViewer.ReportSource = webSource

CRViewer.ViewReport
End Sub
-->
</SCRIPT>

</BODY>
</HTML>


Then I opened the ViewReport.asp from the Internet Explorer, I can see the ActiveX viewer, but the report is not displayed in it. I am sure that the datasource name is correct and that the report is also correct, because when I replace the
webSource.URL = &quot;rptserver.asp&quot;
with
webSource.URL = &quot;ReportName.rpt?user0=UserName&password0=Password&quot;
I can see the report normally.

Can you please help?
Thank you
 
I think the problem seems to be the blank value in
crtable.SetLogonInfo &quot;DSN&quot;, &quot;&quot;, cstr(userid), cstr(password).
When you type the original rpt file in url value.SCR will search the database you marked in THE DESIGN SECTION OF THE REPORT.
 
That's why your report worked in your second attempt I think...
 
crtable.SetLogonInfo &quot;DSN&quot;, &quot;&quot;, cstr(userid), cstr(password)

There's nothing inherently wrong with this statement, as long as &quot;DSN&quot; is defined as a System DSN on the web server and correctly points to the database.
 
balves : You may be right.After all I had stated that I wasn't sure if that had been the solution.Now let's come to the subject of the matter.There is no syntax error in asp.Because the active x is viewed succesfully.Also the report works in when the token webSource.URL = &quot;ReportName.rpt?user0=UserName&password0=Password&quot; is used.
But there is an important thing.In my application enviroment we prefer to use platform independent systems so I use database native drivers and in my system there is no ODBC.
If menazbk uses native database drivers ,that could be a reason.
I will also recheck my Asp codes again and let you know.
 
I have also tried:
crtable.SetLogonInfo &quot;DSN&quot;, &quot;DBName&quot;, cstr(userid), cstr(password),
but also it didn't work.
And in my case I won't be able to connect natively because I am using a VC++ COM object which deals with different types of database engines, and all I can get from it is the connection info which is the DSN, database name, user id and user password.
Can you help please?
Thank you

 
You don't have to use a DSN:

crtable.SetLogonInfo &quot;Servername&quot;, &quot;DBName&quot;, cstr(userid), cstr(password)

If you are running V8.0 there was a problem with registry settings and ODBC for Crystal Web Services. There's a fix on the Crystal web site.


It doesn't have to be a login problem. Are you sure that you're specifying the report path correctly on the web server:

Path = &quot;Physical Path & Report Name.rpt&quot;
Set session(&quot;oRpt&quot;) = session(&quot;oApp&quot;).OpenReport(Path, 1)
 
I have tried without the DSN but still it is not working.
I downloaded and ran the fixing bugs exe and zip files from

but still it does not work. I am logging with the machine Administrator account, so I don't think it is a security problem.
I am also sure that report path is correct.

Thank you
 
I don't know how to pass parameters from VB to crysytal report.
I am using the crystal report 4.6
In properties i saw a sql query .In it query i have given but it did't take the query from VB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top