ConnectionManager.SetExpression(String, String) 메서드

정의

지정한 식을 속성에 할당합니다. 속성에서 기존 식을 제거하려면 null을 지정합니다.

public:
 virtual void SetExpression(System::String ^ propertyName, System::String ^ expression);
public void SetExpression (string propertyName, string expression);
abstract member SetExpression : string * string -> unit
override this.SetExpression : string * string -> unit
Public Sub SetExpression (propertyName As String, expression As String)

매개 변수

propertyName
String

식을 할당할 속성의 이름입니다.

expression
String

식입니다.

구현

예제

다음 코드 예제에서는 식을 사용하여 연결 관리자에 한정된 속성의 값을 설정하는 방법을 보여줍니다. 연결 관리자에 고유한 속성이 컬렉션에 Properties 포함됩니다.

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);   
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace ConnMgr_Properties_Collection  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
        ' The package is one of the SSIS Samples.  
        Dim mySample As String = "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"  

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

        ' Get the Properties collection from the connection manager.  
        Dim myConnMgr As ConnectionManager = myConns(0)  
        Dim connProperties As DtsProperties = myConnMgr.Properties  

        ' View information about the RetainSameConnection property  
        ' before setting it using the SetExpression method.  
        Dim hasProperty As [Boolean] = connProperties.Contains("RetainSameConnection")  
        Console.WriteLine("has RetainSameConnection? {0}", hasProperty)  
        Dim myValue As [Object] = myConnMgr.Properties("RetainSameConnection").GetValue(myConnMgr)  
        Dim mySValue As String = myValue.ToString()  
        Console.WriteLine("value before is {0}", mySValue)  
        Dim myTrueString As String = "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.  
        Dim valResult As DTSExecResult = pkg.Validate(myConns, Nothing, Nothing, Nothing)  

        ' 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)  
        End Sub  
    End Class  
End Namespace  

샘플 출력:

RetainSameConnection이 있나요? 참

이전 값은 False입니다.

값이 True이면

설명

propertyName 연결 관리자 개체의 경우 연결 문자열, 설명, 이름 또는 보호 수준이 될 수 있습니다. 연결 관리자의 경우 현재 식을 지원하는 유일한 속성입니다. 이러한 일반적인 연결 관리자 속성 외에도 각 연결 형식에는 고유한 속성이 있습니다. 이러한 속성은 컬렉션에 Properties 의해 나열됩니다. 메서드를 SetExpression 사용하여 매개 변수로 String 설정할 속성의 이름을 제공할 수 있습니다. 컬렉션을 사용하여 Properties 연결에 고유한 속성을 설정하려는 경우 이 속성 컬렉션이 상속 DtsProperty된다는 것을 아는 것이 유용할 수 있습니다. 상속된 항목은 SetExpressionDtsProperty 첫 번째 매개 변수가 Object 아니라 첫 번째 매개 변수로 String사용합니다.

적용 대상