how to debug the business method

4 posts, 0 answers
  1. Mohammed
    Mohammed avatar
    87 posts
    Member since:
    Aug 2011

    Posted 08 Mar 2013 Link to this post

    Hi team,
    I use an object data source in my report and when I check the preview mode I get an error but if I use the report in report viewer in aspx and run the page i don't get any error.

    first i want to know how to debug my business method when I use the preview mode in my report to not always have to run my aspx screen to do the debugging process.

    second i want why i get this error, kindly find below the details :

    my business method is very simple :
            public List<CreatedQRCodesCountBEL> GetCreatedQRCodesCount(int SuperAcctID) { //my code } 

    in my report i have one report parameter "SuperAcctID" and i just give it a default value no binding to data source:
    An error has occurred while processing Report 'rptCreatedQRCodesCount':
    An error occurred while invoking data retrieval method.
    Try restarting Visual Studio. ------------- InnerException -------------
    Exception has been thrown by the target of an invocation. -------------
    InnerException ------------- Object reference not set to an instance of an object.

    in my aspx code behind i do the below and it is working without the error:

    protected void Page_Load(object sender, EventArgs e)  {
            if (!IsPostBack) {
                var objCreatedQRCodesCountReport = new rptCreatedQRCodesCount();
                objCreatedQRCodesCountReport.ReportParameters["SuperAcctID"].Value = SuperAcctID.ToString();
                radrvCreatedQRCodesCount.ReportSource = objCreatedQRCodesCountReport;

    I hope you can help me.
  2. Peter
    Peter avatar
    1631 posts

    Posted 12 Mar 2013 Link to this post

    Hi Mohammed,

    To debug your DAL while you are using the VS designer you have to open another Visual Studio instance, select Debug->Attach to process to debug another instance of devenv.exe and select Debug->Exception... to enable  the First Chance Exceptions

    Up to the errors the Visual Studio Report Designer operates inside the Visual Studio application. Thus when previewing a report the report constructor is executed in the context of the Visual Studio application. As described in MSDN,  the ConfigurationManager.ConnectionStrings property "gets the  ConnectionStringsSection data for the current application's default configuration". Generally in case of Visual Studio this is devenv.exe.config. However the SqlDataSource component manage to get the connection strings that are added in the currents project configuration file.

    It seems that because you have used a custom data access layer (DAL) to access your database data and your DAL is reading the ConfigurationManager.ConnectionStrings from the report that is previewed you get all connection strings defined in the devenv.exe.config file. In order to avoid the error you have several options:

    1. Hard code the ConnectionString
    2. Use an actual application to view your reports in runtime instead of the Previews.
    3. Use the SqlDataSource instead that will handle the ConnectionStrings in the Class Library's app.config no matter it's name.
    the Telerik team

    Telerik Reporting Q1 2013 available for download with impressive new visualizations. Download today from your account.

  3. K
    K avatar
    10 posts
    Member since:
    Jan 2013

    Posted 10 Apr 2013 Link to this post

    I am having the same problem as described above.  I would like to hard code the connection string so I can use existing business logic in designer preview mode.  Can you clarify how to find and hard code the connection string?

    In my web.config, I only have entity model connection strings, such as

    <add name="MyEFModel1" connectionString="Modemetadata=res://*/DAL.EFModels.MyEFModel1.csdl|res://*/DAL.EFModels.MyEFModel1.ssdl|res://*/DAL.EFModels.MyEFModel1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=sqldev1;Initial Catalog=MySQLDb;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
    <add name="MyEFModel2" connectionString="Modemetadata=res://*/DAL.EFModels.MyEFModel2.csdl|res://*/DAL.EFModels.MyEFModel2.ssdl|res://*/DAL.EFModels.MyEFModel2.msl;provider=System.Data.SqlClient;provider connection string="Data Source=sqldev1;Initial Catalog=MySQLDb;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />

    I think the code that belongs below the InitializeComponent() call should look something like this;
    // Retrieve the connection string settings from the configuration file.
        ConnectionStringSettings connectionSettings = ConfigurationManager.ConnectionStrings["???"];
    // If a valid connection string setting exist, then we are at run-time,
    // so we should use this connection string to connect to the database.
         if (null != connectionSettings)
              // throw it at runtime if you want to see what the connection string for sure is at runtime
                  throw new System.ArgumentException("not null", connectionSettings.ConnectionString);
     // If no valid connection string setting exist, then we are at design-time,
     // so return a default connection string for preview and testing purposes.         
          ConfigurationManager.ConnectionStrings["???"].ConnectionString = "?????"

    I don't know what values to put in place of the  "???"s.   In the report designer, my objectDataSource1.DataSource = MyProject.BLL.MyBLObject, and this is enough to work at run-time, but doesn't make sense in the code above.

    Thanks in advance,
  4. Squall
    Squall avatar
    180 posts
    Member since:
    Feb 2011

    Posted 15 Apr 2013 Link to this post

    You have to open the entity connection with the connection string as explained here:

Back to Top