I am using telerik for reporting in my web application. I have 2 projects
1. ReportLibrary
2. Web application
I have my connection string in web.config file of my web application project.
As I have used reporing wizard to create my reports.....it saved new connection string in app.config file.
I want to use the same connection string which is there in the web.config file.
So How do we do that?
any answer would be appreciated.
10 Answers, 1 is accepted
DatabaseDataSetTableAdapter1.Connection.ConnectionString =
WebConfigurationManager
.ConnectionStrings["MyConnectionStringName"].ConnectionString;
I have the same problem, can anybody from Telerik help?
Thanks
Awais
You'll have to copy the connectionString from the app.config file of the class library to the web.config of the web application project in order to use it.
Kind regards,
Steve
the Telerik team
BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >
web-application(web.config)
--
<appSettings>
<!--Connection strings-->
<add key="Main.Connectionstring" value="Persist Security Info=True;User ID={0};Password={1};Initial Catalog={2};Data Source={3}" />
<add key="DB" value="datastore2" />
<add key="SERVER" value="machine89\sql2008" />
<add key="USER" value="admin" />
<add key="PASSWORD" value="zFxRTQ6vbj+KRJVVbJANuQ==" />
<!--End Connection strings-->
--
Report Library(app.config)
--
<connectionStrings>
<add name="CS.ReportLibrary.Properties.Settings.TestDatabase"
connectionString="Data Source=machine89\SQL2008;Initial Catalog=TestDatabase;Persist Security Info=True;User ID=admin;Password=newt0n$sigm@"
providerName="System.Data.SqlClient" />
</connectionStrings>
--
How do i move the connection string from app.config and put it in web.config, by making sure i don't have to change the way(format) connection-string is set in the web.config?
Thanks
SN
Our suggestion is to use the ConfigurationManager class to read your configuration settings and to assembly a connection string according to the .NET provider requirements. Then in the report's constructor you can set the connection string to the SqlDataSource component instances.
However if you prefer to set the connection string from the client application check out the following code snippet:
static
Report GetReport()
{
Report report =
//retrieve and deserialize the report definition
//Set the new connection string to all data items
SetConnectionString(connectionString, report);
return
report;
}
static
void
SetConnectionString(
string
connectionString, ReportItemBase reportItemBase)
{
if
(reportItemBase
is
Report)
{
var report = (Report)reportItemBase;
if
(report.DataSource
is
SqlDataSource)
{
var sqlDataSource = (SqlDataSource)report.DataSource;
sqlDataSource.ConnectionString = connectionString;
}
foreach
(var parameter
in
report.ReportParameters)
{
if
(parameter.AvailableValues.DataSource
is
SqlDataSource)
{
var sqlDataSource = (SqlDataSource)parameter.AvailableValues.DataSource;
sqlDataSource.ConnectionString = connectionString;
}
}
}
foreach
(var item
in
reportItemBase.Items)
{
//recursively set the connection string to the items from the Items collection
SetConnectionString(connectionString, item);
//Covers Crosstab, Table and List data items
if
(item
is
Table)
{
var table = (Table)item;
if
(table.DataSource
is
SqlDataSource)
{
var sqlDataSource = (SqlDataSource)table.DataSource;
sqlDataSource.ConnectionString = connectionString;
continue
;
}
}
if
(item
is
Chart)
{
var chart = (Chart)item;
if
(chart.DataSource
is
SqlDataSource)
{
var sqlDataSource = (SqlDataSource)chart.DataSource;
sqlDataSource.ConnectionString = connectionString;
continue
;
}
}
if
(item
is
SubReport)
{
var subReport = (SubReport)item;
if
(subReport.ReportSource.DataSource
is
SqlDataSource)
{
var sqlDataSource = (SqlDataSource)subReport.ReportSource.DataSource;
sqlDataSource.ConnectionString = connectionString;
continue
;
}
}
}
}
}
Peter
the Telerik team
BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >
Do you have code samples to accomplish this? VB.NET is preferred. Just getting my legs in C#. I have my report library created in separate project. The website has not been converted to web app (inherited project). I need to have the connection string work for local dev machine and use web site web.config connection string in live site. Can you point me in the right direction for code examples to accomplish this?
Bryan.
If you don't keep the connection string information in the application settings (Properties/Settings.settings), our suggestion is to copy the app.config connection strings to the web.config connectionStrings section with the necessary changes for the live site. The only part of the connection string that should stay the same is its name.
Greetings,Peter
the Telerik team
BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >