Export (0) Print
Expand All

ConnectionManager.SetExpression Method

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 void SetExpression(
	string propertyName,
	string expression
)

Parameters

propertyName
Type: String
The name of the property to assign the expression to.
expression
Type: String
The expression.

Implements

IDTSPropertiesProvider.SetExpression(String, String)

The propertyName for the connection manager object can be a connection string, description, name, or protection level. For the connection manager, those are currently the only properties that support expressions. Besides these common connection manager properties, each connection type has properties that are unique. These properties are listed by the Properties collection. You can use the SetExpression method to provide the name of the property to set as a String parameter. If you want to set properties that are unique to the connection by using the Properties collection, it may be useful to know that this properties collection inherits from DtsProperty. Notice that the SetExpression inherited from DtsProperty takes an Object as the first parameter, not a String.

The following code example shows how to use an expression to set the value of a property that is specific to a connection manager. The properties unique to the connection manager are contained in the Properties collection.

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 onto the property.
            DTSExecResult valResult = pkg.Validate(myConns, null, null, null);
            
            // Now that the value has been set, retrieve it.
            myValue = myConnMgr.Properties["RetainSameConnection"].GetValue(myConnMgr);
            mySValue = myValue.ToString();
            Console.WriteLine("value after is {0}", mySValue); 
        }
    }
}

Sample Output:

has RetainSameConnection? True

value before is False

value after is True

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft