Using Web.Config file for connection string

4 posts, 0 answers
  1. Sumit
    Sumit avatar
    9 posts
    Member since:
    Apr 2011

    Posted 29 Aug 2011 Link to this post

    We were using following method to get connection string in Crystal Reports:

       private void SetDBLogonForReport(ReportDocument myReportDocument, string[] credentials)
                Tables myTables = myReportDocument.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in myTables)
                    TableLogOnInfo myTableLogonInfo = myTable.LogOnInfo;

                    myTableLogonInfo.ConnectionInfo.ServerName = credentials[0];
                    myTableLogonInfo.ConnectionInfo.DatabaseName = credentials[1];
                    myTableLogonInfo.ConnectionInfo.UserID = credentials[2];
                    myTableLogonInfo.ConnectionInfo.Password = credentials[3];

                    myTable.Location = "myDatabase.dbo." + Session["RptView"];
                rptVwer.ReportSource = myReportDocument;

    How can we do something similar in Telerik report?
    Thank you in advance.
  2. Peter
    Peter avatar
    1629 posts

    Posted 31 Aug 2011 Link to this post

    Hello Sumit,

    Do you want to set the data source component's connection string from the client application? If this is the case then Telerik Reporting reports are regular .NET classes and to achieve your requirement our suggestion is to expose the SqlDataSource.ConnectionString with a public property as shown in the following code snippets:

    public string ConnectionString
            this.sqlDataSource1.ConnectionString = value;

    var report = new ReportDynamicConnectionString();
    report.ConnectionString = @"Data Source=.\SQLEXPRESS2008;Initial Catalog=AdventureWorks;Integrated Security=True";
    this.ReportViewer1.Report = report;

    Hope this helps.

    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 15 Dec 2011 Link to this post


    I have my connection strings in a separate file like so:
    <connectionStrings configSource="Web.DatabaseConnectionStrings.config" />

    The wizard cannot see this apparently and keeps adding connection strings in the web.config, generating errors.

  4. Steve
    Steve avatar
    10941 posts

    Posted 16 Dec 2011 Link to this post

    Hello Erik,

    SqlDataSource Wizard searches for existing database connections in Server Explorer and in the configuration file of the current project. For example, if you have a separate class library project for your reports, the wizard searches for connection strings only in the App.config file of that project. If you have your connection string specified in the Web.config file of another project, you need to copy it to the App.config file of the report class library as well, otherwise the wizard cannot discover it. This is done for a reason: since a solution may contain many different projects, each of them with its own configuration file, it is unknown which one might contain the correct connection string for your report, so we simply pick the configuration file of the current project where the report is located. Moreover this behavior allows you to use two different databases for development and for production. For example, the database used for development and testing purposes might be a local one, while the actual production database might be situated on a dedicated database server.

    the Telerik team

    Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Back to Top