Crystal Reports Connection string from web.config

Posted on 2006-05-22
Last Modified: 2012-06-21
Dear Experts
I am using VS.NET 2005, ASP.NET 2.0, C#, SQLSERVER2000
I want to use Crystal Reports, but the problem I found is that,
I can’t give to the report while I am creating it from the wizard the connection string in the web.config
I need help or any ideas thank you

Thank you

Question by:RamzyEbeid
    1 Comment
    LVL 7

    Accepted Solution


    I'm using VS.NET 2002 and ASP.NET 1.0 and VB, and CR 9.0 so things might be different... but here's some snippets on how I'm using settings from Web.Config to load my report...  When creating the report I used OLEDB(ADO), Microsoft OLE DB Provider for for SQL Server, and connect to my development DB.  The code below allows me to change that connection info:

    In Web.Config:

          <!-- connection string -->
          <add key="strServer" value="YourServer" />
          <add key="strDBase" value="YourDB" />
          <add key="strUID" value="YourUID" />
          <add key="StrPWD" value="YourPassword" />

    In my module to Logon to the report:

    Public Sub LogonReport(ByVal rptReport As CrystalDecisions.CrystalReports.Engine.ReportDocument)
    'Logs into the tables in the report
            crReportDocument = rptReport
            crDataBase = crReportDocument.Database
            crTables = crDataBase.Tables
            For Each crTable In crTables
                With crConnInfo
                    .ServerName = ConfigurationSettings.AppSettings("strServer")
                    .DatabaseName = ConfigurationSettings.AppSettings("strDBase")
                    .UserID = ConfigurationSettings.AppSettings("strUID")
                    .Password = ConfigurationSettings.AppSettings("strPWD")
                End With

                crTableLogonInfo = crTable.LogOnInfo
                crTableLogonInfo.ConnectionInfo = crConnInfo
                crTable.Location = strDBase & ".dbo." & crTable.Name
    Also logon to subreport tables....

    In my .aspx page to load the report:

    crReportDocument.Load(Server.MapPath("") & ReportName)
    Call LogonReport(crReportDocument)

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now