Click here to Skip to main content
Licence CPOL
First Posted 18 Jan 2008
Views 25,575
Downloads 311
Bookmarked 21 times

Crystal Report database connection in ASP.NET

By | 18 Jan 2008 | Article
In this article I am going to discuss how to use UDL file with Crystal Report to connect particular database.

Introduction

In this article I am going to discuss how to use UDL file with Crystal Report to connect particular database.

Using the code

What is UDL?

Universal Data Link files (.udl files) can be used to store information of connection string. So it works as a common user interface for specifying connection attributes.

How to create a UDL file?

  1. Open a notepad and save it using .udl extension. (Note: don not write anything in that notepad). Udl_Creation.JPG 2. Now it displays with small computer icon.

udl_file.JPG
3. Now you should configure your udl file. Double click on the udl file. Now it displays as follows.
udl_Configure_1.JPG
4. Now select a provider. In this example I have used Microsoft SQL server 2005 express edition. So I need to use Microsoft OLE DB Provider for SQL Server as the provider. Then click Next button or Connection tab.

5.Then you will have to select details which related to SQL server. After providing those data, you can check connection is success or not by clicking Test Connection button.

Now you can add crystal report to your project. Select OLE DB (ADO) as the data source of the project.

Report_Configure1.JPG

Then display OLE DB (ADO) dialog box. Now select use data link file and browse your .udl file.

Report_Configure2.JPG

After configuring data source, you can add SQL query to crystal report by double clicking AddCommand. Now you can SQL query here.

Report_Configure3.JPG

After creating crystal report you can display it on your asp.net web page. For that you have to add CrystalReportViwer control to your web page. After then write following code in the code behind page.

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;



using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using CrystalDecisions.Web;

public partial class _Default : System.Web.UI.Page 

{

    ReportDocument doc;

    protected void Page_Load(object sender, EventArgs e)

    {

        try
        {
            doc = new ReportDocument();

            doc.Load(MapPath("~\\TestReport.rpt"));



            CrystalReportViewer1.ReportSource = doc;

        }

        catch (Exception ex)

        {

            Label1.Text = ex.Message;

        }

    }

}

         

Points of Interest

You can use the for windows based application development also.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Manjula Wickramathunga

Other
Creative Technology Solutions Pte Ltd
Sri Lanka Sri Lanka

Member

Manjula Wickramathunga currently is working at Creative Technology Solutions Private Limited as a Consultant. He is working with Microsoft Technologies such as C#, MS SQL server 2000,2005 and 2008, ASP.NET 2.0/3.5/4.0.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 Pinmemberbhagyap0:04 29 Dec '11  
GeneralMy vote of 5 PinmemberPankaja Kanavi21:10 28 Dec '11  
GeneralThanks Pinmembertkjbbs13:15 11 Jun '08  
GeneralMS SQL SERVER EXPRESS 2005 AND CRYSTAL REPORT PinmemberAP Software8:36 14 Feb '08  
GeneralRe: MS SQL SERVER EXPRESS 2005 AND CRYSTAL REPORT PinmemberManjula Wickramathunga16:54 14 Feb '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 18 Jan 2008
Article Copyright 2008 by Manjula Wickramathunga
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid