Click here to Skip to main content
13,343,731 members (64,184 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


23 bookmarked
Posted 18 Jan 2008

Crystal Report database connection in ASP.NET

, 18 Jan 2008
Rate this:
Please Sign up or sign in to vote.
In this article I am going to discuss how to use UDL file with Crystal Report to connect particular database.


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?<o:p />

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? <o:p />

  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.

3. Now you should configure your udl file. Double click on the udl file. Now it displays as follows.
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.


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


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


After creating crystal report you can display it on your 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)


            doc = new ReportDocument();


            CrystalReportViewer1.ReportSource = doc;


        catch (Exception ex)


            Label1.Text = ex.Message;




Points of Interest

You can use the for windows based application development also.


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


About the Author

Manjula Wickramathunga
Team Leader Midas Safety Inc
Sri Lanka Sri Lanka
Manjula Wickramathunga currently is working at Midas Safety Inc as a Senior Consultant Integration Services. He is working with SAP and Microsoft Technologies such as C#, MS SQL server, ASP.NET, ASP.NET MVC, WebAPI.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
bhagyap29-Dec-11 1:04
memberbhagyap29-Dec-11 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 18 Jan 2008
Article Copyright 2008 by Manjula Wickramathunga
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid