LogProvider.SetExpression Method (String, String)


Assigns the specified expression to the property. Specify null to remove an existing expression from the property.

Namespace:   Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

Public Sub SetExpression (
	propertyName As String,
	expression As String


Type: System.String

The name of the property to which to assign the expression.

Type: System.String

The expression.

The propertyName will be ConfigString, Description, or Name. For the log provider, those are currently the only three properties that can use an expression.

The following example sets the Description property of the log provider to be the text, "This is the log for…" with the current month and day appended to the end of the string.

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime

Namespace LogProvider_Expression_Tests
    Class Program
        Shared Sub Main(ByVal args() As String)
            ' The package is one of the SSIS Samples. The package was
            ' modified to log to the SSIS log provider for Text files
            ' and saved before loading into this code.
            Dim mySample As String = "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"

            ' Create the Application, and load the sample.
            Dim app As New Application()
            Dim pkg As Package = app.LoadPackage(mySample, Nothing)

            ' Get the LogProviders collection.
            Dim logProvs As LogProviders = pkg.LogProviders

            ' Get the "SSIS log provider for Text files"
            ' provider from the collection.
            Dim textLogProv As LogProvider = logProvs("SSIS log provider for Text files")

            'Display the current description of this provider.
            Dim currDescription As String = textLogProv.Description
            Console.WriteLine("Current description: {0}", currDescription)

            ' Set an expression. Only a few properties
            ' are available to have expressions. For Log Providers, 
            'current only the properties of ConfigString, Description,
            ' and Name take expressions.
            Dim dt As DateTime = DateTime.Now
            Dim nowMonth As String = dt.ToString("m")
            Dim newDesc As String = """This is the log for " + nowMonth + """"
            textLogProv.SetExpression("Description", newDesc)

            ' Validate the package to set the expression
            ' onto the property.
            Dim pkgConns As Connections = pkg.Connections
            Dim valResult As DTSExecResult = pkg.Validate(pkgConns, Nothing, Nothing, Nothing)
            If valResult <> DTSExecResult.Failure Then
                Console.WriteLine("Validation passed: {0}", valResult)
                Console.WriteLine("Validation FAILED: {0}", valResult)
            End If
            ' Retrieve the log provider collections.
            logProvs = pkg.LogProviders

            ' Retreive the text log provider from the collection.
            textLogProv = logProvs("SSIS log provider for Text files")

            ' Check the expression, and verify that the name changed.
            Dim logProvExpr As String = textLogProv.GetExpression("Description")
            Console.WriteLine("The expression for Description is {0}", logProvExpr)
            Dim newDescAfter As String = textLogProv.Description
            Console.WriteLine("The description is now: {0}", newDescAfter)
        End Sub
    End Class
End Namespace

Sample output:

Current description: Writes log entries for events to a CSV file

Validation passed: Success

The expression for Description is "This is the log for January 06"

The description is now: This is the log for January 06

Return to top