ForEachSMOEnumerator.GetEnumerator Method
Returns an enumerator that can iterate through the ForEachSMOEnumerator instance.
네임스페이스: Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO
어셈블리: Microsoft.SqlServer.ForEachSMOEnumerator (in microsoft.sqlserver.foreachsmoenumerator.dll)
구문
‘선언
Public Overrides Function GetEnumerator ( _
connections As Connections, _
variableDispenser As VariableDispenser, _
events As IDTSInfoEvents, _
log As IDTSLogging _
) As Object
public override Object GetEnumerator (
Connections connections,
VariableDispenser variableDispenser,
IDTSInfoEvents events,
IDTSLogging log
)
public:
virtual Object^ GetEnumerator (
Connections^ connections,
VariableDispenser^ variableDispenser,
IDTSInfoEvents^ events,
IDTSLogging^ log
) override
public Object GetEnumerator (
Connections connections,
VariableDispenser variableDispenser,
IDTSInfoEvents events,
IDTSLogging log
)
public override function GetEnumerator (
connections : Connections,
variableDispenser : VariableDispenser,
events : IDTSInfoEvents,
log : IDTSLogging
) : Object
매개 변수
- connections
A collection of connections used by the SMO enumerator.
- variableDispenser
A VariableDispenser object for locking variables.
- events
An object that implements the IDTSInfoEvents interface.
- log
An object that implements the IDTSLogging interface.
반환 값
An object that is subsequently cast to an IEnumerator object.
예
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 SMOEnumerator is created as a System.Collections.IEnumerator and iterated over using MoveNext and Current. After the collection has passed the end, 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 SMOEnumerator
{
class Program
{
const string PACKAGEFILENAME = @"\SamplePackage.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.DTSDesigner90;
package.Name = "SMOEnumerator Sample";
package.Description = "This is a sample for SMOEnumerator";
package.CreatorComputerName = @"MACHINENAME"; // System.Environment.MachineName;
package.CreatorName = @"USERNAME"; //System.Environment.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";
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='Tables']"
+ @"/SMOEnumType[@Name='ObjectsPP']";
System.Collections.IEnumerator smoEnumerator = (System.Collections.IEnumerator)forEachSMOEnumerator.GetEnumerator(
connections, null, null, null);
Console.WriteLine("The collection contains the following values:");
int i = 0;
while ((smoEnumerator.MoveNext()) && (smoEnumerator.Current != null))
Console.WriteLine("[{0}] {1}", i++, smoEnumerator.Current);
smoEnumerator.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 SMOEnumerator
Class Program
const String PACKAGEFILENAME = "\SamplePackage.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.DTSDesigner90
package.Name = "SMOEnumerator Sample"
package.Description = "This is a sample for SMOEnumerator"
package.CreatorComputerName = "MACHINENAME" ' System.Environment.MachineName;
package.CreatorName = "USERNAME" 'System.Environment.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"
Dim forEachEnumeratorInfo As ForEachEnumeratorInfo = application.ForEachEnumeratorInfos("Foreach SMO Enumerator")
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='Tables']"
Dim "/SMOEnumType[@Name='ObjectsPP']" As +
System.Collections.IEnumerator smoEnumerator = (System.Collections.IEnumerator)forEachSMOEnumerator.GetEnumerator(
connections, Nothing, Nothing, Nothing)
Console.WriteLine("The collection contains the following values:")
Dim i As Integer = 0
While (smoEnumerator.MoveNext()) &&(smoEnumerator.Current <> Nothing)
Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
End While
smoEnumerator.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
스레드 보안
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
플랫폼
개발 플랫폼
지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.
대상 플랫폼
지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.
참고 항목
참조
ForEachSMOEnumerator Class
ForEachSMOEnumerator Members
Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO Namespace