Posted 14 September 2017, 7:03 pm EST
[activereports_archive]Hi Prakash,
Yes, you can create a global key in element of a web.config file to define the connection string and further use it wherever required using “System.Configuration.ConfigurationManager.AppSettings”.
In web.config file, you can make the appSetting entry to hold the connection string:
<appSettings>
<add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Windows8.1\Documents\GrapeCity Samples\ActiveReports 10\Data\Reels.mdb;Persist Security Info=False" />
</appSettings>
Further, you can access it using 'System.Configuration.ConfigurationManager’class and define the datasource of the report:
[csharp] protected void Button1_Click(object sender, EventArgs e)
{
SectionReport rpt1 = new SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath(“~/SectionReport1.rpx”));
rpt1.LoadLayout(xtr);
xtr.Close();
string connString = ConfigurationManager.AppSettings["ConnectionString"];
conn = new System.Data.OleDb.OleDbConnection(connString);
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("Select * from Customer", conn);
conn.Open();
reader = cmd.ExecuteReader();
rpt1.DataSource = reader;
rpt1.Run();
WebViewer1.Report = rpt1;
}[/csharp]
Please refer to the attach sample implementing the same.
Let me know if you faces any confusion.
Best Regards,
Shubham Srivastava[/activereports_archive]
2015/11/AR_GlobalConnectionString.zip