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

Problem when trying to preview reports

3 Answers 190 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
أشرف
Top achievements
Rank 1
أشرف asked on 18 Aug 2014, 07:04 AM
Greetings,

I'm using Telerik Reporting version 8.1.14.804 (Q2 2014 SP1) in an ASP.Net Web Forms application, inside Visual Studio 2012 (Ultimate 2012 Version 11.0.61030.00  Update 4).
I created a simple report that fetches data from an entity data source that uses a DbContext class in the project.

The report works as expected, but in design time, when I try to preview it, an error message is displayed saying:
An error has occurred while processing Table 'table1': An error occurred while
invoking data retrieval method. Try restarting Visual Studio. -------------
InnerException ------------- No connection string named 'DbContext' could be
found in the application config file.


Where DbContext is the name of my code first context class.

I uploaded a demo web application that demonstrates the problem here:
http://www.wikifortio.com/825288/ReportsSample.zip
I removed the bin directory but Nuget should settle this.

How to resolve this issue?

3 Answers, 1 is accepted

Sort by
0
Accepted
Stef
Telerik team
answered on 20 Aug 2014, 11:47 AM
Hi Ashraf,

In the DbContext you need to add a second constructor accepting a string parameter, which will be used by the EntityDataSource component to pass the connection string from the component configuration.
namespace TelerikReportsPlayground.Data
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
 
    public partial class DbContext : System.Data.Entity.DbContext
    {
        public DbContext()
            : base("name=DbContext")
        {
        }
 
        public DbContext(string connstr)
            : base(connstr)
        {
        }
 
        public virtual DbSet<Department> Departments { get; set; }
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
        }
    }
}


For more details please go through the EntityDataSource Component overview article.


Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
أشرف
Top achievements
Rank 1
answered on 21 Aug 2014, 08:14 AM
This resolves the problem. Thank you.

But I have a question: The documentation page you pointed me to says "If Code First is used there is no need for a constructor with string parameter" and I use code first in my project. I wonder what's the need for a connection string? Why not the designer just instantiate the DbContext and fetch data from it? Specially that the report works at run time without providing a connection string.
0
Stef
Telerik team
answered on 26 Aug 2014, 11:06 AM
Hello Ashraf,

If you set your model as follows you can omit the second constructor, and specify the already existing model's connection string by name:
<!-- connectin string saved during creating the data model -->
 <connectionStrings>
    <add name="DbContext" connectionString="data source=.\SQLEXPRESS;initial catalog=AdventureWorks;Integrated Security=SSPI;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>
......................
//the model settings
namespace TelerikReportsPlayground.Data
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
 
    public partial class DbContext : System.Data.Entity.DbContext
    {
        public DbContext()
            : base("DbContext")
        {
        }     
................................
//the EntityDataSource component settings
            //
            // entityDataSource1
            //
            this.entityDataSource1.ConnectionString = "DbContext";
            this.entityDataSource1.Context = typeof(TelerikReportsPlayground.Data.DbContext);
            this.entityDataSource1.ContextMember = "Departments";
            this.entityDataSource1.Name = "entityDataSource1";
        public virtual DbSet<Department> Departments { get; set; }
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
        }
    }
}



Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
أشرف
Top achievements
Rank 1
Answers by
Stef
Telerik team
أشرف
Top achievements
Rank 1
Share this question
or