次の方法で共有


ConnectionManager.SetExpression メソッド

指定した式をプロパティに割り当てます。 既存の式をプロパティから削除するには、nullNULL 参照 (Visual Basic では Nothing) を指定します。

名前空間:  Microsoft.SqlServer.Dts.Runtime
アセンブリ:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS.dll)

構文

'宣言
Public Sub SetExpression ( _
    propertyName As String, _
    expression As String _
)
'使用
Dim instance As ConnectionManager 
Dim propertyName As String 
Dim expression As String

instance.SetExpression(propertyName, _
    expression)
public void SetExpression(
    string propertyName,
    string expression
)
public:
virtual void SetExpression(
    String^ propertyName, 
    String^ expression
) sealed
abstract SetExpression : 
        propertyName:string * 
        expression:string -> unit  
override SetExpression : 
        propertyName:string * 
        expression:string -> unit
public final function SetExpression(
    propertyName : String, 
    expression : String
)

パラメーター

  • propertyName
    型: System.String
    式を割り当てるプロパティの名前です。

実装

IDTSPropertiesProvider.SetExpression(String, String)

説明

接続マネージャー オブジェクトの propertyName には、接続文字列、説明、名前、または保護レベルを指定できます。 接続マネージャーの場合、現在、式をサポートするプロパティは、これらのみです。 共通の接続マネージャー プロパティ以外にも、各接続の種類には一意のプロパティがあります。 これらのプロパティは、Properties コレクションによって一覧表示されます。 SetExpression メソッドを使用してプロパティの名前を指定し、String パラメーターとして設定することができます。 Properties コレクションを使用して、接続に一意のプロパティを設定する場合は、このプロパティ コレクションが DtsProperty から継承されることを知っていると便利です。 DtsProperty から継承された SetExpression は、最初のパラメーターとして String ではなく Object を取ることに注意してください。

使用例

次のコード例では、式を使用して、接続マネージャーに固有のプロパティの値を設定します。 接続マネージャー固有のプロパティは、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

サンプルの出力 :

has RetainSameConnection? True

value before is False

value after is True

関連項目

参照

ConnectionManager クラス

Microsoft.SqlServer.Dts.Runtime 名前空間