Iron Speed Technical Forums
Register Latest Topics
 
 
 


Reply
  Author   Comment   Page 1 of 2      1   2   Next
echo4sos

Avatar / Picture

MVP Developer
Registered:
Posts: 172
Reply with quote  #1 

Integrating Crystal Reports Viewer with Iron Speed

       Part 1 -How to add a Crystal Reports Viewer control to ISD pages

Bill Goodwin

Iron Speed MVP

June 7, 2012

Iron Speed Designer v9.x

 

Introduction

 

In this article I will demonstrate the basics on how to integrate a Crystal Reports Viewer control into your Iron Speed application. I will not discuss passing parameters to the report, as this is an advanced topic. The Crystal Reports Viewer control is not affiliated with the Crystal Reports Code Customization Wizard included in Iron Speed. There is no need for a Crystal Reports button from Iron Speed, as this control will enable users to be able to view Crystal Reports embedded into an aspx page.

Implementation

 

The development environment used for this demonstration is as follows: Windows 7 Enterprise 32-bit, Visual Studio 2010 SP1, and Crystal Reports for Visual Studio SP3 (included with Visual Studio 2010, but should be updated via this download: SAP Crystal Reports, version for Visual Studio 2010 - Standard). Please note*: This scenario will not work and is not intended for use with Visual Studio Web Developer edition, since Crystal Reports is not available with VSWD.

This article is based on generating an application in Iron Speed 9.0.1 with the targeted .NET framework of 4.0, using VB.NET as the programming language.

  1. Create a new application in Iron Speed Designer.
  2. Create a new blank page in your application.
  3. Build your application.
  4. Open your application in Visual Studio using the button provided in ISD.
  5. Create a new Crystal Report in Visual Studio. From Solution Explorer in VS 2010, right click on the folder where you created the blank page in step 2 and select Add New Item.
  6. Select Crystal Reports. Name the report. Click the Add button.
  7. Create your Crystal Report using the Crystal Reports Gallery wizard.
  8. Open up the blank aspx page created in Step 2 in Visual Studio.
  9. From the Visual Studio toolbox under Reporting, drag and drop a CrystalReportSource component to your aspx page between the [TD] tags in the main table.
  10. Configure the CrystalReportSource using its Smart Tag to bind to the Crystal Report created in Step 7.
  11. From the Visual Studio toolbox under Reporting, drag and drop a CrystalReportViewer component to your aspx page under the CrystalReportSource.
  12. Configure the CrystalReportViewer using its Smart Tag to bind to the CrystalReportSource.
  13. Copy the CrystalReportSource and CrystalReportViewer sections from Visual Studio and paste into a cell in your blank page in ISD.
  14. Take notice how the SmartTag for the CrystalReportSource generates the FileName attribute. This should be changed. For example, my FileName attribute was generated as “Contracts\CrystalReport.rpt”, but should be changed to “CrystalReport.rpt”. We do not need to specify the folder path, as the report file resides in the same directory. This is incorrectly generated in Visual Studio. Be sure to change it to the correct path.
  15. Switch back to your page in Visual Studio. Copy the assembly information generated by Visual Studio when you created the CrystalReportSource.
  16. Paste this into your Page Directives on your ISD page. (Right click any cell and select Page Directives). This code should be placed before any other code.
  17. Save and build your application. You may need to repeat Step 16, as for some reason the Page Directives may not save initially.
  18. View your web.config file in ISD. Take notice of the Crystal Reports assembly version information. You will need to change the version information in Step 16 to match the version information in your web.config file. Otherwise, you’ll get an “Ambiguous Namespace” error message.
  19. Save and build your application.
  20. We need to add a bit of code in the code-behind file of the viewer page to set the database logon information for the report. Switch to the code-behind file of your page in ISD and add the following code to the bottom of Section 1.


    [CODE]
    Protected Sub CrystalReportSource1_Load(sender As Object, e As System.EventArgs) Handles CrystalReportSource1.Load
    CrystalReportSource1.ReportDocument.SetDatabaseLogon("sqltest", "sqltest")
    End Sub
    [/CODE]
  21. Change the “username” and “password” parameters to the same logon information used to connect your Crystal Report to your database in Step 7.
  22. Save and build your application. You can now run the report viewer page and see your newly created Crystal Report Viewer.


 

Conclusion

I have demonstrated the basics of adding a Crystal Report Viewer component to an Iron Speed Designer generated application. In the next installment of this article I will go into more advanced scenarios, such as passing report parameters and configuring the application to run on a production server, to include proper settings in IIS.

 

Iron Speed Designer is very flexible and accepting of various customizations. Iron Speed Designer creates the framework, you supply the imagination!

I hope you enjoyed this article. If you have any questions or comments, feel free to post them in this article’s forum page.

Attached Images
Click image for larger version - Name: 1.jpg, Views: 2569, Size: 44.27 KB  Click image for larger version - Name: 2.jpg, Views: 2541, Size: 7.42 KB  Click image for larger version - Name: 3.jpg, Views: 2558, Size: 39.57 KB  Click image for larger version - Name: 4.jpg, Views: 2552, Size: 103.79 KB  Click image for larger version - Name: 5.jpg, Views: 2549, Size: 43.10 KB  Click image for larger version - Name: 6.jpg, Views: 2536, Size: 72.51 KB  Click image for larger version - Name: 7.jpg, Views: 2531, Size: 28.63 KB  Click image for larger version - Name: 8.jpg, Views: 2533, Size: 94.30 KB  Click image for larger version - Name: 9.jpg, Views: 2538, Size: 57.57 KB  Click image for larger version - Name: 10.jpg, Views: 2526, Size: 34.49 KB  Click image for larger version - Name: 11.jpg, Views: 2504, Size: 45.59 KB  Click image for larger version - Name: 12.jpg, Views: 2514, Size: 125.27 KB  Click image for larger version - Name: 13.jpg, Views: 2532, Size: 44.76 KB  Click image for larger version - Name: 14.jpg, Views: 2504, Size: 43.36 KB 

 
Attached Files
doc Integrating_Crystal_Reports_Viewer_with_Iron_Speed.doc (280.00 KB, 453 views)


__________________
-Bill

rawales2

Registered:
Posts: 96
Reply with quote  #2 
Man- this is great!  Been looking for good instructions like this for a long time.

Appreciate it!

__________________
Rob
You can code your own way...
echo4sos

Avatar / Picture

MVP Developer
Registered:
Posts: 172
Reply with quote  #3 
Thanks, Rob! Eventually at some point I'll get around to demonstrating how to pass variables to the reports, but real life is kind of hectic right now. If you have any questions or problems, feel free to ask.
__________________
-Bill
Wouter

Registered:
Posts: 3
Reply with quote  #4 
Great tutorial Bill!

I ran into one (probably easy to solve;-)) problem with step 20 (providing the sever credentials). I am using C# and inserted the following function in the code-behind file of my custom page
Code:
 protected void CrystalReportSource1_Load(object sender, System.EventArgs e) { CrystalReportSource1.ReportDocument.SetDatabaseLogon("USER", "PASS"); CrystalReportSource1.ReportDocument.SetParameterValue("MyParam", "Mass Combi - Test"); }



When I test this I get a failed to log on error. If i copy both functions in the page_load function (temporary in section 2) it all works fine. But the page_load function can not be overridden do you have any idea want I'm doing wrong?


Ps. As you can see I'm also experimenting with passing parameters to the reports so I'm really looking forward to your next tutorial!
echo4sos

Avatar / Picture

MVP Developer
Registered:
Posts: 172
Reply with quote  #5 
Is there any way you can debug this through VS? You may need to pass two more variables to the SetDatabaseLogon method... CrystalReportSource1.ReportDocument.SetDatabaseLogon("USER", "PASS", "YOURSERVER", "YOURDATABASE");

The other two parameters specify the SQL server name and database implicitly. Try that and let me know how it goes.

__________________
-Bill
adiaz1

Registered:
Posts: 3
Reply with quote  #6 
Hi Bill

It is a great tutorial!

The report is working fine,  but in the last part, I have some issues
I am using C#

Can you help me ?



Thanks
Antonio

Attached Images
Click image for larger version - Name: Error.jpg, Views: 1815, Size: 32.17 KB 

__________________
International Rectifier Corporation
Rectificadores Internacionales S.A. de C.V.
Prol. Av. de los Cabos #9234
Parque. Ind. Pacifico II
Tijuana, B.C., México

echo4sos

Avatar / Picture

MVP Developer
Registered:
Posts: 172
Reply with quote  #7 
Hi Antonio,

Please make sure that your Crystal Report Source is actually named: "CrystalReportSource1"

If you are not using Visual Studio with the intellisense feature, you have to manually ensure that the object names match each other (as named in Iron Speed).

If you are using Visual Studio, you can open up the page's code-behind and use the intellisense by preceding the CrystalReportSource1 with "this.")

I hope that makes sense.

__________________
-Bill
adiaz1

Registered:
Posts: 3
Reply with quote  #8 
Hi Bill

The Crystal Report Source is actually named: "CrystalReportSource1




 With Visual Studio using the intellisense by preceding the CrystalReportSource1





On Visual Studio Design mode look like this



On the web application look like this




Any idea?


Thanks for your help
Regards
Antonio



Attached Images
Click image for larger version - Name: Error3.jpg, Views: 1800, Size: 73.47 KB  Click image for larger version - Name: Error2.jpg, Views: 1820, Size: 122.16 KB  Click image for larger version - Name: Error4.jpg, Views: 9, Size: 79.56 KB  Click image for larger version - Name: Error5.jpg, Views: 1779, Size: 51.90 KB  Click image for larger version - Name: Error6.jpg, Views: 1798, Size: 69.84 KB 

__________________
International Rectifier Corporation
Rectificadores Internacionales S.A. de C.V.
Prol. Av. de los Cabos #9234
Parque. Ind. Pacifico II
Tijuana, B.C., México

echo4sos

Avatar / Picture

MVP Developer
Registered:
Posts: 172
Reply with quote  #9 
Hey Antonio,

Make sure that you have included a reference to the Crystal Reports Assemblies in your page code-behind (HandlersReport.aspx.cs)...

Using CrystalDecisions.Shared
Using CrystalDecisions.CrystalReports.Engine
Using CrystalDecisions.Web

Also, make sure that the following assembly references are in your web.config file...

<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>

In Iron Speed, check in your page directives of your HandlersReport.aspx (right click on any cell and select Page Directives) and make sure that you have the following reference:

<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

__________________
-Bill
Jonesy

Registered:
Posts: 10
Reply with quote  #10 
Hi
Brilliant, clear, concise tutorial. Thank you.
Works perfectly for me on my development machine under localhost but on deploying to a web server I get a broken site and a message -

Internal Server Error
 
The requested web page either has an error or does not exist.

Please contact your system administrator or customer support.


On removing the report and all web config references to Crytal the site works perfectly on the server. Something I'm doing is wrong but I've checked each step many times and scoured the Page Directives, web confi file etc for errors but none are apparent.

Would greatly appreciate your continued indulgence.
Thanks
Chris
 
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,929
Reply with quote  #11 
Make sure your host is supporting Crystal Reports.
__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

Jonesy

Registered:
Posts: 10
Reply with quote  #12 
Did not even think of that, thank you.
I'm with DiscountAsp.net and after searching it appears they DON'T support Crystal Reports.
Would you have any recommendations?
Chris
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,929
Reply with quote  #13 
I believe there are plenty nowadays  (you can search) - unlike before, one of the reason why I shifted to Telerik Reporting.

Cheers,
Jimi J




__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

Jonesy

Registered:
Posts: 10
Reply with quote  #14 

Thanks Jimi J
I've tried 2 other hosting companies that host CR and still having problems.
I'm thinking of changing to Telerik as you did.
Could you tell me if Telrik reporting requires special hosting or any other special requirement and is it user friendly with ironspeed?
Since there is a cost involved to change I want to ensure I don't waste a heap more time.
Thanks very much
Chris

wyldKard

Avatar / Picture

Registered:
Posts: 54
Reply with quote  #15 
Hi folks, 

I know this is an old post, and I recently worked on integrating a Crystal Report Viewer and found this thread. I encountered the same problem "CrystalReporSource1 does not exist in the current context" to adiaz1's post while working on the backend of C#. Found a similar problem and solution/explanation from this post by gcook17 on VB code:

Code:

Protected WithEvents CrystalReportSource1 As Global.CrystalDecisions.Web.CrystalReportSource


here's the C# converted code generated using Telerik's code converter. Place this on the Section 1 of your code behind. 

Code:

    private global::CrystalDecisions.Web.CrystalReportSource withEventsField_CrystalReportSource1;
    protected global::CrystalDecisions.Web.CrystalReportSource CrystalReportSource1
    {
        get { return withEventsField_CrystalReportSource1; }
        set
        {
            if (withEventsField_CrystalReportSource1 != null)
            {
                withEventsField_CrystalReportSource1.Load -= CrystalReportSource1_Load;
            }
            withEventsField_CrystalReportSource1 = value;
            if (withEventsField_CrystalReportSource1 != null)
            {
                withEventsField_CrystalReportSource1.Load += CrystalReportSource1_Load;
            }
        }
    }



For reference's sake, hope this helps other users the way it helped me. Thanks

PS not sure why I can't directly drag a CrystalReportsSource and CrystalReportViewer object to the code like the way this tutorial says in ISD v12.2.0 and VS 2010. I still have a copy of v9.1.1 and the dragging works.

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Download Iron Speed Designer

Terms of Service Privacy Statement