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

Telerik Reporting, EntityDatasource, Runtime setting of DbContext

1 Answer 306 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 06 Apr 2015, 08:10 PM

hi,

we're struggled quite a lot with building telerik reports using the new Q1 2015 report builder and are hopefully at the final hurdle.

We've built a report using an entitydatasource pointed at a function written in the DbContext project, GetOrderById(int id). This produces an invoice output which now works in the designer.

When we run it in our application using the webforms report viewer (for compatability purposes) it keeps trying to create a local database instead of reading the sql server connection of the context we've passed in to it.

 

Here is the runtime code that i've bound to the page_load event of a page (for getting it working purposes)

Dim source = New Telerik.Reporting.UriReportSource()
        source.Uri = "web/apps/shared/InvoiceReport2.trdx"
 
 
        Dim report = New Telerik.Reporting.Report
 
        Dim ds As New EntityDataSource()
        Dim context = New DataContext(connectionString) // passed in as a text string and is 100% valid
 
        ds.Context = context
        ds.ContextMember = "GetOrderForReports"
        ds.Parameters.Add("OrderId", GetType(Integer), 89720)
 
        report.DataSource = ds
        ReportViewer1.ReportSource = source
        ReportViewer1.RefreshReport()

the error we get is as below. any help would be great, cheers.

An error has occurred while processing Report 'invoicereport2': An error occurred while invoking data retrieval method. ------------- InnerException ------------- Exception has been thrown by the target of an invocation. ------------- InnerException ------------- Directory lookup for the file "D:\xxxxxx\WebSites\xxxxx\App_Data\xxxxx.mdf" failed with the operating system error 2(The system cannot find the file specified.). CREATE DATABASE failed. Some file names listed could not be created. Check related errors. 

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 08 Apr 2015, 12:51 PM
Hello Jack,

I believe we are discussing the same question in another private thread. For anyone concerned, below is quote from my response:

"................
To set the data you can:
  • Deserialize the TRDX file into Telerik.Reporting.Report object and set all data items' DataSource properties:
    'deserialize the TRDX file
    Dim settings = New System.Xml.XmlReaderSettings()
    settings.IgnoreWhitespace = True
    Dim reportInstance As Telerik.Reporting.Report
    Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(HttpContext.Current.Server.MapPath("MyTRDXFile.trdx"), settings)
        Dim xmlSerializer = New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
        reportInstance = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)
    End Using
     
    'set the report's DataSource
    reportInstance.DataSource = GetReportData()
     
    'set a nested item's DataSource
    TryCast(reportInstance.Items.Find("graph1", True)(0), Telerik.Reporting.Graph).DataSource = GetGraphData()
     
    'create a report source object
    Dim irs = New InstanceReportSource
    irs.ReportDocument = reportInstance
     
    'display the report
    reportViewer1.ReportSource = irs
  • If you have worked with the data model in the Standalone Designer, configure the start project in the same manner. On displaying the report, the reporting engine will search for the same assembly as the loaded in the Standalone Designer.

    Extend the Standalone Designer to work with the data model.
    You will have to add both your assemblies and the EF assemblies to the config file of the Designer. For more information please check the Extending Report Designer help article. For example:

    <Telerik.Reporting>
       <AssemblyReferences>
           <add name="MyCustomAssembly" version="1.0.0.0" culture="neutral" publicKeyToken="null" />
           <add name="EntityFramework" version="6.0.0.0" culture="neutral" publicKeyToken="..." />
           <add name="EntityFramework.SqlServer" version="6.0.0.0" culture="neutral" publicKeyToken="..." />
       </AssemblyReferences>
    </Telerik.Reporting>
    The config file is situated in the same folder as the exe file of the Designer, which is usually C:\Program Files (x86)\Telerik\Reporting Q1 2015\Report Designer. The assemblies must be copied next to the designer's exe file.

    Extending the application to deploy the TRDX files.
    The same settings must be applied in the start project with the viewer. Reference the assemblies related to the data model, and extend the configuration with a Telerik.Reporting section - Deploying trdx (XML report definition) that uses external assembly.

    This approach is suitable to avoid modifications in the report. You can use your data model via EntityDataSource component e.g., the data retrieval approaches illustrated in Retrieving data from an Entity Data Model with the EntityDataSource component. This will allow you to filter the data  via report parameters mapped to the data-retrieval method's arguments - EntityDataSource Wizard (steps 5 and 6) and Using parameters with the EntityDataSource component.

​ In both cases you can use the data-binding approaches from How to use the ReportItem.DataObject property in expressions and How to Databind to Collection Properties for nested data items.
..............
"

Regards,
Stef
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
General Discussions
Asked by
Jack
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or