다음을 통해 공유


SMODataFileEnumerator.Current 속성

Gets the current object from the enumerator.

네임스페이스:  Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO
어셈블리:  Microsoft.SqlServer.ForEachSMOEnumerator(Microsoft.SqlServer.ForEachSMOEnumerator.dll)

구문

‘선언
Public ReadOnly Property Current As Object 
    Get
‘사용 방법
Dim instance As SMODataFileEnumerator 
Dim value As Object 

value = instance.Current
public Object Current { get; }
public:
virtual property Object^ Current {
    Object^ get () sealed;
}
abstract Current : Object 
override Current : Object
final function get Current () : Object

속성 값

유형: System.Object
An object that is the current object in the collection.

구현

IEnumerator.Current

The following code example creates a ForEachLoop, creates a SMO enumerator and hosts it in a ForEachEnumeratorHost, where it is then added as the ForEachEnumerator in the ForEachLoop. Returning a ForEachSMOEnumerator, a SMODataFileEnumerator is created as a System.Collections.IEnumerator and iterated over using MoveNext and Current. After the index has passed the end of the collection, the Reset is used to reset the iterator.

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

namespace SmoDataFileEnumerator
{
    class Program
    {
        const string PACKAGEFILENAME = @"\SmoDataFileEnumeratorPackage.dtsx";
        static void Main(string[] args)
        {
            // Create the SSIS application
            Application application = new Application();

            // Create the new package
            Package package = new Package();
            package.PackageType = DTSPackageType.DTSDesigner;
            package.Name = "SMODataFileEnumerator Sample";
            package.Description = "This is a sample for SMODataFileEnumerator";
            // Use System.Environment.MachineName; in the following line of code.
            package.CreatorComputerName = @"MACHINENAME";
            // Use System.Environment.UserName; in the following line of code.
            package.CreatorName = @"USERNAME";

            // Adds the ADO.NET connection manager to the package
            Connections connections = package.Connections;
            ConnectionManager connectionManager = connections.Add("ADO.NET:SQL");
            Console.WriteLine("ConnectionManager creation name: {0}", connectionManager.CreationName);
            connectionManager.Name = "localhost.AdventureWorks";
            connectionManager.ConnectionString = "Data Source=localhost;"
                + "Initial Catalog=AdventureWorks;"
                + "Integrated Security=True;";

            // Create ForEach SMO Loop task
            Executables executables = package.Executables;
            ForEachLoop forEachLoop = executables.Add("STOCK:FOREACHLOOP") as ForEachLoop;
            forEachLoop.Name = "Foreach Loop Container";
            forEachLoop.Description = "Foreach Loop Container";

            Console.WriteLine("ForEachLoop creation name: {0}", forEachLoop.CreationName);
            ForEachEnumeratorInfo forEachEnumeratorInfo
                = application.ForEachEnumeratorInfos["Foreach SMO Enumerator"];
            ForEachEnumeratorHost forEachEnumeratorHost = forEachEnumeratorInfo.CreateNew();
            forEachLoop.ForEachEnumerator = forEachEnumeratorHost;

            // Setup the SMO enumerator
            ForEachSMOEnumerator forEachSMOEnumerator = forEachEnumeratorHost.InnerObject as ForEachSMOEnumerator;
            forEachSMOEnumerator.EnumURN = "RuntimeServer[@Connection='"
            + connectionManager.ID + @"']/Server[@Name='localhost']"
                + @"/Database[@Name='AdventureWorks']"
                + @"/SMOEnumObj[@Name='DataFiles']"
                + @"/SMOEnumType[@Name='Locations']";

            System.Collections.IEnumerator smoDataFileEnumerator = forEachSMOEnumerator.GetEnumerator(
            connections, null, null, null) as System.Collections.IEnumerator;
            Console.WriteLine("The collection contains the following values:");
            int i = 0;
            while ((smoDataFileEnumerator.MoveNext()) && (smoDataFileEnumerator.Current != null))
                Console.WriteLine("[{0}] {1}", i++, smoDataFileEnumerator.Current);

            smoDataFileEnumerator.Reset();
            // Validate the layout of the package
            DTSExecResult status = package.Validate(package.Connections, null, null, null);
            Console.WriteLine("Validation result: " + status);

            // Save the package
            String currentDirectory = Environment.CurrentDirectory;
            application.SaveToXml(currentDirectory + PACKAGEFILENAME, package, null);
            Console.WriteLine("Package saved to " + currentDirectory + PACKAGEFILENAME);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO
 
Namespace SmoDataFileEnumerator
    Class Program
        const String PACKAGEFILENAME = "\SmoDataFileEnumeratorPackage.dtsx"
        Shared  Sub Main(ByVal args() As String)
            ' Create the SSIS application
            Dim application As Application =  New Application() 
 
            ' Create the new package
            Dim package As Package =  New Package() 
            package.PackageType = DTSPackageType.DTSDesigner
            package.Name = "SMODataFileEnumerator Sample"
            package.Description = "This is a sample for SMODataFileEnumerator"
            ' Use System.Environment.MachineName; in the following line of code.
            package.CreatorComputerName = "MACHINENAME"
            ' Use System.Environment.UserName; in the following line of code.
            package.CreatorName = "USERNAME"
 
            ' Adds the ADO.NET connection manager to the package
            Dim connections As Connections =  package.Connections 
            Dim connectionManager As ConnectionManager =  connections.Add("ADO.NET:SQL") 
            Console.WriteLine("ConnectionManager creation name: {0}", connectionManager.CreationName)
            connectionManager.Name = "localhost.AdventureWorks"
            connectionManager.ConnectionString = "Data Source=localhost;"
                + "Initial Catalog=AdventureWorks;"
                Dim "Integrated Security=True;" As +
 
            ' Create ForEach SMO Loop task
            Dim executables As Executables =  package.Executables 
            Dim forEachLoop As ForEachLoop =  executables.Add("STOCK:FOREACHLOOP") as ForEachLoop 
            forEachLoop.Name = "Foreach Loop Container"
            forEachLoop.Description = "Foreach Loop Container"
 
            Console.WriteLine("ForEachLoop creation name: {0}", forEachLoop.CreationName)
            ForEachEnumeratorInfo forEachEnumeratorInfo
                Dim  As =
            Dim forEachEnumeratorHost As ForEachEnumeratorHost =  forEachEnumeratorInfo.CreateNew() 
            forEachLoop.ForEachEnumerator = forEachEnumeratorHost
 
            ' Setup the SMO enumerator
            Dim forEachSMOEnumerator As ForEachSMOEnumerator =  forEachEnumeratorHost.InnerObject as ForEachSMOEnumerator 
            forEachSMOEnumerator.EnumURN = "RuntimeServer[@Connection='"
            + connectionManager.ID + "']/Server[@Name='localhost']"
                + "/Database[@Name='AdventureWorks']"
                + "/SMOEnumObj[@Name='DataFiles']"
                Dim "/SMOEnumType[@Name='Locations']" As +
 
            System.Collections.IEnumerator smoDataFileEnumerator = forEachSMOEnumerator.GetEnumerator(
            connections, Nothing, Nothing, Nothing) as System.Collections.IEnumerator
            Console.WriteLine("The collection contains the following values:")
            Dim i As Integer =  0 
            While (smoDataFileEnumerator.MoveNext()) &&(smoDataFileEnumerator.Current <> Nothing)
                Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
            End While

            smoDataFileEnumerator.Reset()
            ' Validate the layout of the package
            Dim status As DTSExecResult =  package.Validate(package.Connections,Nothing,Nothing,Nothing) 
            Console.WriteLine("Validation result: " + status)
 
            ' Save the package
            Dim currentDirectory As String =  Environment.CurrentDirectory 
            application.SaveToXml(currentDirectory + PACKAGEFILENAME, package, Nothing)
            Console.WriteLine("Package saved to " + currentDirectory + PACKAGEFILENAME)
        End Sub
    End Class
End Namespace

참고 항목

참조

SMODataFileEnumerator 클래스

Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO 네임스페이스