Common SSRS Variables and Simultaneous Reporting

We have several SSRS reports that do not fire when two of them run very close together.

I found out that if two instances of an SSRS report are started at the same time, any code variables declared at the class level (not inside the function) may collide. I suspect this may be the reason for our failures in the reports, and I am fixing a potential problem.

The reason we use part of SSRS code in general is about things like calculating custom groups and page titles. Code is called from expressions in TextBoxes and returns the current label. The code must maintain state in order to remember what the value of the last header was in order to return it when it is not known, or to save the new header value for reuse.

Note: here are my resources for a variable collision problem:

SSRS MSDN Forum :

Since it uses static variables, if two people run the report in the exact same moment, there is a subtle chance that will break another state of the variable (In SQL 2000, this may be due to two users viewing the same report at the same time, not only because of precisely simultaneous executions). If you need to be 100% to avoid this, you can make each of the shared variables a hash table based on the user ID (global user ID).

Embedded code in Reporting Services :

... , Count ( ). - , (, ByVal ).

, , , - . , , . ( , .)

, - , . , - InstanceID =Guid.NewGuid().ToString().

, , , Hashtables , Reporting Services.

, , , - . , , , .

, , , - . , :

Private Shared Data As New System.Collections.Hashtable()

Public Shared Function Initialize() As String
   If Not Data.ContainsKey(Parameters!InstanceID.Value) Then
      Data.Add(Parameters!InstanceID.Value, New System.Collections.Hashtable())
   End If
   LetValue("SomethingCount", 0)
   Return ""
End Function

Private Shared Function GetValue(ByVal Name As String) As Object
   Return Data.Item(Parameters!InstanceID.Value).Item(Name)
End Function

Private Shared Sub LetValue(ByVal Name As String, ByVal Value As Object)
   Dim V As System.Collections.Hashtable = Data.Item(Parameters!InstanceID.Value)
   If Not V.ContainsKey(Name) Then
      V.Add(Name, Value)
   Else
      V.Item(Name) = Value
   End If
End Sub

Public Shared Function SomethingCount() As Long
   SomethingCount = GetValue("SomethingCount") + 1
   LetValue("SomethingCount", SomethingCount)
End Function
  • - . , , , , . Dim _sht as System.Collections.Hashtable = System.Collections.Hashtable.Synchronized(_hashtable). ? Mutex? ? .

  • , System.Collections Hashtable , System.Collections , " ", System.Collections". , , .

  • , , . OnInit, : OnInit .

  • Data New, , , ( - , ).

  • Shared. ? , , , , , . ... - , Shared SSRS?

  • ? GetValue, , , -?

  • Hashtables, , InstanceID , -?

, / , .

!

+3
1

. () - . InstanceID, Globals.ExecutionTime User.UserID.

, , :

Private Shared Data As System.Collections.Hashtable 

If Data Is Nothing Then
   Set Data = Hashtable.Synchronized(New System.Collections.Hashtable())
End If

- , , .

+1

Source: https://habr.com/ru/post/1728514/


All Articles