次の方法で共有


ExportConfigurationFile メソッド

パッケージ内の配置可能なすべての変数を含む XML ファイルを作成します。

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

構文

'宣言
Public Sub ExportConfigurationFile ( _
    str As String _
)
'使用
Dim instance As Package
Dim str As String

instance.ExportConfigurationFile(str)
public void ExportConfigurationFile(
    string str
)
public:
void ExportConfigurationFile(
    String^ str
)
member ExportConfigurationFile : 
        str:string -> unit 
public function ExportConfigurationFile(
    str : String
)

パラメーター

説明

構成ファイルを編集し、コンピュータ依存の変数の値を変更できます。パッケージが別のコンピュータに配置されるたび、実行時に、そのコンピュータのコンピュータ依存の変数を使用します。詳細については、「パッケージの構成の作成」を参照してください。

使用例

次の例では、新しいパッケージを作成し、EnableConfigurations を true に設定して、ExportConfigurationFile プロパティを設定します。次に、パッケージに新しい構成を追加し、ConfigurationStringConfigurationType、および PackagePath の値を設定します。

static void Main(string[] args)
        {
            // Create a package and set two properties.
            Package pkg = new Package();
            pkg.EnableConfigurations = true;
            pkg.ExportConfigurationFile(@"C:\conf.xml");

            // Create a variable object and add it to the 
            // package Variables collection.
            Variable varPkg = pkg.Variables.Add("var", false, "", 100);
            varPkg.Value = 1;
            string packagePathToVariable = varPkg.GetPackagePath();

            // Create a configuration object and add it to the 
           // package configuration collection
            Configuration config = pkg.Configurations.Add();

           // Set properties on the configuration object.
            config.ConfigurationString = "conf.xml";
            config.ConfigurationType = DTSConfigurationType.ConfigFile;
            config.PackagePath = packagePathToVariable;

            //save the package and its configuration
            Application app = new Application();
            app.SaveToXml(@"c:\pkg.xml", pkg, null);
            
            //Reload the package
            Package p1 = app.LoadPackage(@"c:\pkg.xml", null);
            //Review its Variables collection
            Console.WriteLine("The value of variable VAR = " + p1.Variables["var"].Value);
        }
Shared  Sub Main(ByVal args() As String)
            ' Create a package and set two properties.
            Dim pkg As Package =  New Package() 
            pkg.EnableConfigurations = True
            pkg.ExportConfigurationFile("C:\conf.xml")
 
            ' Create a variable object and add it to the 
            ' package Variables collection.
            Dim varPkg As Variable =  pkg.Variables.Add("var",False,"",100) 
            varPkg.Value = 1
            Dim packagePathToVariable As String =  varPkg.GetPackagePath() 
 
            ' Create a configuration object and add it to the 
           ' package configuration collection
            Dim config As Configuration =  pkg.Configurations.Add() 
 
           ' Set properties on the configuration object.
            config.ConfigurationString = "conf.xml"
            config.ConfigurationType = DTSConfigurationType.ConfigFile
            config.PackagePath = packagePathToVariable
 
            'save the package and its configuration
            Dim app As Application =  New Application() 
            app.SaveToXml("c:\pkg.xml", pkg, Nothing)
 
            'Reload the package
            Dim p1 As Package =  app.LoadPackage("c:\pkg.xml",Nothing) 
            'Review its Variables collection
            Console.WriteLine("The value of variable VAR = " + p1.Variables("var").Value)
End Sub

サンプルの出力 :

The value of variable VAR = 1