This is a migrated thread and some comments may be shown as answers.

Using Web.Config file for connection string

3 Answers 846 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sumit
Top achievements
Rank 1
Sumit asked on 29 Aug 2011, 05:26 AM
Hi,
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.ApplyLogOnInfo(myTableLogonInfo);
                myTable.Location = "myDatabase.dbo." + Session["RptView"];
            }
            rptVwer.ReportSource = myReportDocument;
        }

How can we do something similar in Telerik report?
Thank you in advance.
Sumit

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 31 Aug 2011, 06:12 PM
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
{
    set
    {
        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.

Greetings,
Peter
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 >>

0
Erik
Top achievements
Rank 2
answered on 15 Dec 2011, 07:30 PM
Peter,

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.

Erik
0
Steve
Telerik team
answered on 16 Dec 2011, 12:25 PM
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.

Regards,
Steve
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!

Tags
General Discussions
Asked by
Sumit
Top achievements
Rank 1
Answers by
Peter
Telerik team
Erik
Top achievements
Rank 2
Steve
Telerik team
Share this question
or