Set TimeOut to a ReportViewer

/ Published in: VB.NET
Save to your folder(s)

I have a Report Viewer on an ASPX Form that uses an Object Data Source / Data Set that connects to a SQL Server Database Stored Procedure. Depending on the parameters sent to the procedure, it will take longer than 30 seconds to run, thus generating the following error:

An error occurred during local report processing.
An error has occurred during report processing.
Exception has been thrown by the target of an invocation.
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Copy this code and paste it in your HTML
  1. 'I figured out how to do this. I had to piece together help from a few different places, 'but it works.
  3. '1. I added a typed dataset (dsCaseReport) to my project to hold the datatable (dtCaseRpt) 'and tableadapter (taCaseRpt) tied to my SQL stored procedure.
  4. '2. I added a new class (clsCaseRpt) that I use to override the default timeout of taCaseRpt 'since you can't do it via the designer. This code allows you to change the 'connectionstring timeout to 0 (which is unlimited) before you fill the dataset. Here is 'the code for that class.
  5. Imports Microsoft.VisualBasic
  6. Namespace dsCaseReportTableAdapters
  7. Partial Public Class taCaseRpt
  8. Public Property ConnectionString() As String
  9. Get
  10. Return Me.Connection.ConnectionString
  11. End Get
  12. Set(ByVal value As String)
  13. Me.Connection.ConnectionString = value
  14. End Set
  15. End Property
  17. Public Sub SetCommandTimeout(ByVal timeout As Integer)
  18. If Me.Adapter.InsertCommand IsNot Nothing Then
  19. Me.Adapter.InsertCommand.CommandTimeout = timeout
  20. End If
  22. If Me.Adapter.DeleteCommand IsNot Nothing Then
  23. Me.Adapter.DeleteCommand.CommandTimeout = timeout
  24. End If
  26. If Me.Adapter.UpdateCommand IsNot Nothing Then
  27. Me.Adapter.UpdateCommand.CommandTimeout = timeout
  28. End If
  30. For i As Integer = 0 To Me.CommandCollection.Length - 1
  31. If Me.CommandCollection(i) IsNot Nothing Then
  32. Me.CommandCollection(i).CommandTimeout = timeout
  33. End If
  34. Next
  35. End Sub
  36. End Class
  37. End Namespace
  38. '3. Then instead of assigning the reportviewer (rvCase) to an Object Data Source on the 'page, I programmatically assign it to the dataset during the page load (or during any other 'sub). Here is the code for that. Note: I specify a Case ID parameter when filling my 'dataset. That is what the intCaseID variable is for. Also, notice that I call the 'SetCommandTimeout sub with the 0 parameter before filling the dataset. This overrides the 'default 30 second timeout. Finally, I assign the dataset as a new datasource to the 'reportviewer control.
  39. Dim taCaseRpt As New dsCaseReportTableAdapters.taCaseRpt
  40. Dim dsCaseReport As New dsCaseReport
  41. Dim intCaseID As Integer = 2
  42. taCaseRpt.SetCommandTimeout(0)
  43. taCaseRpt.Fill(dsCaseReport.dtCaseRpt, intCaseID)
  44. rvCase.LocalReport.DataSources.Clear()
  45. rvCase.LocalReport.DataSources.Add(New ReportDataSource("dsCaseReport_dtCaseRpt", dsCaseReport.Tables(0)))
  46. 'Now it doesn't matter how long it takes for the stored procedure to run, my program will 'wait and the reportviewer will display once it is finished. I think I covered everything, 'but let me know if you have questions.


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.