I am trying to generate pdf from dynamically from the database which is sqlserver.
i am using the entityframework
But
when i am clicking on report after all code done its telling like System.InvalidOperation No ConectionString Name DynamicReportDemoEntity Could be found in app config
this is the error screen shot
============================================
this is my ReportingStartupCode
public class ReportingStartup
{
public void Configure(IVSReportingConfiguration configuration)
{
//var connectionString = ConfigurationManager.ConnectionStrings["ReportsDBEntities"].ConnectionString;
// ReportsDBEntities db = new ReportsDBEntities(@"server=pranjal;database=ADO;uid=sa;password=123;");
var db = new DynamicReprtDemoEntities(@"data source=pranjal;initial catalog=DynamicReprtDemo;user id=sa;password=123;MultipleActiveResultSets=True;App=EntityFramework"");
var data = db.GetData();
configuration.RegisterSampleData("dynamic", db.GetData());
}
}
=======================================
This is my MainMethode Code
class Program
{
static void Main(string[] args)
{
IEmbeddedReportingServer embeddedServer = new EmbeddedReportingServer() ;
embeddedServer.StartAsync().Wait();
embeddedServer.ReportingService.SynchronizeTemplatesAsync().Wait();
var result = embeddedServer.ReportingService.RenderAsync("Report1", new
{
template = new Template()
{
content = "<table><tr><td>Hello World</td></tr></table>",
}
}).Result;
using (var fs = File.Create(@"f:\pdf\pranjal.pdf"))
{
result.Content.CopyTo(fs);
}
}
=====================================================
This is my contextclass code
public partial class DynamicReprtDemoEntities : DbContext
{
public DynamicReprtDemoEntities(string Name)
: base("name=DynamicReprtDemoEntities")
{
}
public DynamicReprtDemoEntities() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Department> Departments { get; set; }
public object GetData()
{
return new
{
Departments = Departments.Include(d => d.Dept).Select(d => new
{
Id = d.ID,
Name = d.Name,
Department = d.Dept,
Company = d.Company
}).ToList()
};
}
}
====================================
connection string present under the config file please see
<connectionStrings>
<add name="DynamicReprtDemoEntities" connectionString="metadata=res:///MyDataBase.csdl|res:///MyDataBase.ssdl|res://*/MyDataBase.msl;provider=System.Data.SqlClient;provider connection string="data source=pranjal;initial catalog=DynamicReprtDemo;user id=sa;password=123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>