Storing an active reports format in the Database

Storing an active reports format in the Database

Old forum URL: forums.lhotka.net/forums/t/414.aspx


alandotnet posted on Monday, June 19, 2006

Hi,

I was wondering if there was anyone who has ever stored a report format in the database and retrieved that report from the DB as a stream and converted it to a usable report object at runtime? Or has anyone got any ideas how i would firstly get the report format into the DB and secondly how I would then convert the read memory stream to a usable report object that i can call the constructor on?

I am using active reports 2.0 but if anyone has done this with another reporting product i would still love to know.

Thanks

Alan

Marjon1 replied on Tuesday, June 20, 2006

I've been implementing this using a business object and devexpress xtrareports over the past couple of weeks. We have numerous other properties attached to the business object, but the report itself is created and saved through a single property which returns or accepts an XtraReport object. This converts it to a stream, which I then save to a private string and save to the database with the rest of the object. When I need to return the report I read the private string and then return the report object. Can't say that this is the best way to do it, but it is working great for us.

  Private _Definition As String = String.Empty

  Public Property Report() As XtraReport
    Set(ByVal value As XtraReport)
      Dim Stream As MemoryStream = New MemoryStream()
      value.SaveLayout(Stream)

      Stream.Position = 0

      Using sr As New StreamReader(Stream)
        _Definition = sr.ReadToEnd
      End Using

    End Set
    Get
      Using sw As New StreamWriter(New MemoryStream())
        sw.Write(_Definition)
        Return XtraReport.FromStream(sw.BaseStream, False)
      End Using
    End Get
  End Property

Brian Criswell replied on Tuesday, June 20, 2006

We do this by using the third party designer and saving the resulting XML to a text field in the database.  I would recommend that you just design your reports as objects though.  You lose a bit of design-time functionality using the third party designer control, especially in the realm of sub reports.

Copyright (c) Marimer LLC