How to declare a global connection string for AR

Posted by: prakash1234 on 14 September 2017, 7:03 pm EST

    • Post Options:
    • Link

    Posted 14 September 2017, 7:03 pm EST

    [activereports_archive]Hi,

    Currently I’m passing connection string to every RPX file, but I want to make it global, so that i can create a key in web.config file in my project and pass it to all RPX files.

    Is there any way to do so.

    Thank You!!

    Prakash[/activereports_archive]

  • 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

  • Posted 6 June 2020, 1:56 am EST

    Hello,

    How do I put my connection string in my web config in AR 14? How do I access it from code? In the report designer, do I remove the connection string?

  • Posted 8 June 2020, 11:55 am EST

    Hello,

    Your query has been replied here:

    https://supportone.componentone.com/casedetail/439777

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels