Explore a DataList Spec (CLR)

Let's take a quick look at a DataListSpec that calls on a custom .NET class. The .NET class that you develop will be a server-side catalog implementation that will retrieve and organize the rows within the data list. Both the spec file and the .NET class file should reside within the server-side catalog .NET project. A server-side catalog indicates the code will execute on the Infinity web/application server and not on the client machine. This spec includes a CLRDataList element that contains the AssemblyName and ClassName attributes. The AssemblyName attribute denotes the assembly that contains the catalog feature code. The ClassName attribute contains the name of the class within the assembly that contains the catalog feature code. This class should inherit the Blackbaud.AppFx.Server.AppCatalog.AppDataList class. Within the class public memory, variables are used as the parameters for the CLR data list. Within the DataListSpec XML file, you can see the parameter list that maps to the public memory variables. When the code is executed, the GetListResults() function is automatically invoked. When GetListResults() is invoked, a System.Collections.Generic.List (A generic list represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists) of Blackbaud.AppFx.Server.DataListResultRow is populated and used to return a list of rows for the data list in the form of a Blackbaud.AppFx.Server.AppCatalog.AppDataListResult.

Figure: Sample CLR data list spec (Part 1 of 2): The Test CLR DataListSpec calls custom server side .NET code

Figure: Sample CLR data list spec (Part 2 of 2): The TestCLRDataList.vb .NET class

Tip:

While not utilized in the figure above, it is important to close your SQLConnection. See below.

Closing Connections

Sometimes your code requires an unmanaged resource, such as a SQL connection. If the SqlConnection goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose. You may also consider a Using block which guarantees the disposal of one or more such resources when your code is finished with them. For more information see http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.close.aspx and http://msdn.microsoft.com/en-us/library/htd05whh.aspx.

For example, the following code would require the explicit closing of the connection:

Dim conn As SqlConnection = Me.RequestContext.OpenAppDBConnection
		‘code to perform work with the sql connection 
conn.Close

Whereas utilizing a Using block guarantees the disposal of the SQLConnection:

using conn As SqlConnection = Me.RequestContext.OpenAppDBConnection
	‘code to perform work with the sql connection
end using