I stepped through the report event and noted that the NeedDataSource fires whenever I press preview from the Report viewer. I do notice however, that the NeedDataSource event fires again when I do an export from the report viewer. This event is where I set the report.DataSource, this also means that this is where I run the database queries.
I would have thought that since the report.DataSource has already been set/cached during the "preview" action (through the NeedDataSource), the "export to excel" action will not cause the NeedDataSource event to fire again. This is a winforms application by the way so asp.net statelessness is not an issue.
You see, I have a fairly large monthly data set and it takes twice the time to preview the report and export the report because of this NeedDataSource event.
How is the NeedDataSource event triggered? What sets the report.Datasource to nothing?
An example of the NeedDataSource event:
Private Sub MonthlyAccepted_AS_MasterReport_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
Dim subGroupName As ISOSettlementProvisionSubGroupName = EnumUtility(Of ISOSettlementProvisionSubGroupName).Parse(Me.ReportParameters(SETTLEMENT_TYPE).Value)
Dim dayofMonth As Date = Date.Parse(Me.ReportParameters(MONTH).Value & " 1, " & Me.ReportParameters(YEAR).Value)
me.DataSource = BusinessObjects.MonthlyAcceptedASInfo.GetData(dayofMonth, subGroupName)