ConnectionManager.GetExpression Method (String)


Returns a String that contains the expression for the specified property. Null means that no expression has been assigned.

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

public string GetExpression(
	string propertyName


Type: System.String

The name of the property whose expression you want to see.

Return Value

Type: System.String

A String that contains the expression used to evaluate the property.

The propertyName can be a connection string, description, name, or protection level. For the connection manager, these are currently the only properties that support expressions.

Besides those common connection manager properties, each connection type has properties that are unique. These properties are listed by the Properties collection.

The following code example sets an expression on a unique property of the connection manager, and then retrieves it after the package is validated.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace ConnMgr_Properties_Collection
    class Program
        static void Main(string[] args)
            // The package is one of the SSIS Samples.
            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";

            // Create an application and load the sample.
            Application app = new Application();
            Package pkg = app.LoadPackage(mySample, null);
            Connections myConns = pkg.Connections;

            // Get the Properties collection from the connection manager.
            ConnectionManager myConnMgr = myConns[0];
            DtsProperties connProperties = myConnMgr.Properties;

            // View information about the RetainSameConnection property 
            // before setting it using the SetExpression method.
            Boolean hasProperty = connProperties.Contains("RetainSameConnection");
            Console.WriteLine("has RetainSameConnection? {0}", hasProperty);
            Object myValue = myConnMgr.Properties["RetainSameConnection"].GetValue(myConnMgr);
            String mySValue = myValue.ToString();
            Console.WriteLine("value before is {0}", mySValue);
            String myTrueString = "true";

            // Use SetExpression to set the value to true.
myConnMgr.Properties["RetainSameConnection"].SetExpression(myConnMgr, myTrueString);

            // Validate the package to set the expression on the property.
            DTSExecResult valResult = pkg.Validate(myConns, null, null, null);

            // Now that the value has been set, retrieve the value
            // and the expression.
            myValue = myConnMgr.Properties["RetainSameConnection"].GetValue(myConnMgr);
            mySValue = myValue.ToString();
            String myExpression = myConnMgr.Properties["RetainSameConnection"].GetExpression(myConnMgr);
            String mySExpression = myExpression.ToString();
            Console.WriteLine("value and expression is {0}, {1}", mySValue, mySExpression); 

Sample Output:

has RetainSameConnection? True

value before is False

value and expression is True, true

Return to top