SqlBulkCopy 생성자

정의

SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다.

오버로드

SqlBulkCopy(SqlConnection)

SqlConnection의 지정된 열린 인스턴스를 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다.

SqlBulkCopy(String)

제공된 connectionString에 따라 SqlConnection의 새 인스턴스를 초기화하고 엽니다. 생성자는 SqlConnection을 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다.

SqlBulkCopy(String, SqlBulkCopyOptions)

제공된 connectionString에 따라 SqlConnection의 새 인스턴스를 초기화하고 엽니다. 이 생성자는 SqlConnection을 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다. SqlConnection 인스턴스는 copyOptions 매개 변수에 제공된 옵션에 따라 작동합니다.

SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)

제공된 SqlBulkCopy의 이미 열려 있는 인스턴스를 사용하여 SqlConnection 클래스의 새 인스턴스를 초기화합니다. SqlBulkCopy 인스턴스는 copyOptions 매개 변수에 제공된 옵션에 따라 작동합니다. 제공된 SqlTransaction이 null이 아니면 복사 작업이 해당 트랜잭션 내에서 수행됩니다.

SqlBulkCopy(SqlConnection)

SqlConnection의 지정된 열린 인스턴스를 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlBulkCopy(System::Data::SqlClient::SqlConnection ^ connection);
public SqlBulkCopy (System.Data.SqlClient.SqlConnection connection);
new System.Data.SqlClient.SqlBulkCopy : System.Data.SqlClient.SqlConnection -> System.Data.SqlClient.SqlBulkCopy
Public Sub New (connection As SqlConnection)

매개 변수

connection
SqlConnection

대량 복사 작업을 수행하는 데 사용할 이미 열려 있는 SqlConnection 인스턴스입니다. 연결 문자열에서 Integrated Security = true를 사용 중이 아니면 SqlCredential을 사용하여 연결 문자열에서 사용자 ID와 암호를 텍스트로 지정할 때보다 사용자 ID와 암호를 보다 안전하게 전달할 수 있습니다.

예제

다음 콘솔 애플리케이션 데이터 대량 로드는 이미 열려 있는 연결을 사용 하는 방법에 설명 합니다. 이 예제에서는 SqlDataReader를 사용하여 SQL Server AdventureWorks 데이터베이스에 있는 Production.Product 테이블의 데이터를 같은 데이터베이스의 비슷한 테이블로 복사합니다. 이 예제는 예시용입니다. 사용 하지 않을 SqlBulkCopy 프로덕션 애플리케이션에서 동일한 데이터베이스에서 다른 한 테이블에서 데이터를 이동 하 합니다. 원본 데이터는 SQL Server 위치할 필요가 없습니다. 에 읽 IDataReader 거나 로 로드할 수 있는 모든 데이터 원본을 DataTable사용할 수 있습니다.

중요

이 샘플은 가져올 대량 복사 샘플 설정에 설명된 대로 작업 테이블을 만들지 않은 경우 실행되지 않습니다. 이 코드는 SqlBulkCopy를 사용하는 구문을 보여 주는 용도로 제공됩니다. 원본 테이블과 대상 테이블이 동일한 SQL Server instance 있는 경우 Transact-SQL INSERT ... SELECT 문을 사용하여 데이터를 복사하는 것이 더 쉽고 빠릅니다.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = GetConnectionString();
        // Open a sourceConnection to the AdventureWorks database.
        using (SqlConnection sourceConnection =
                   new SqlConnection(connectionString))
        {
            sourceConnection.Open();

            // Perform an initial count on the destination table.
            SqlCommand commandRowCount = new SqlCommand(
                "SELECT COUNT(*) FROM " +
                "dbo.BulkCopyDemoMatchingColumns;",
                sourceConnection);
            long countStart = System.Convert.ToInt32(
                commandRowCount.ExecuteScalar());
            Console.WriteLine("Starting row count = {0}", countStart);

            // Get data from the source table as a SqlDataReader.
            SqlCommand commandSourceData = new SqlCommand(
                "SELECT ProductID, Name, " +
                "ProductNumber " +
                "FROM Production.Product;", sourceConnection);
            SqlDataReader reader =
                commandSourceData.ExecuteReader();

            // Open the destination connection. In the real world you would
            // not use SqlBulkCopy to move data from one table to the other
            // in the same database. This is for demonstration purposes only.
            using (SqlConnection destinationConnection =
                       new SqlConnection(connectionString))
            {
                destinationConnection.Open();

                // Set up the bulk copy object.
                // Note that the column positions in the source
                // data reader match the column positions in
                // the destination table so there is no need to
                // map columns.
                using (SqlBulkCopy bulkCopy =
                           new SqlBulkCopy(destinationConnection))
                {
                    bulkCopy.DestinationTableName =
                        "dbo.BulkCopyDemoMatchingColumns";

                    try
                    {
                        // Write from the source to the destination.
                        bulkCopy.WriteToServer(reader);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        // Close the SqlDataReader. The SqlBulkCopy
                        // object is automatically closed at the end
                        // of the using block.
                        reader.Close();
                    }
                }

                // Perform a final count on the destination
                // table to see how many rows were added.
                long countEnd = System.Convert.ToInt32(
                    commandRowCount.ExecuteScalar());
                Console.WriteLine("Ending row count = {0}", countEnd);
                Console.WriteLine("{0} rows were added.", countEnd - countStart);
                Console.WriteLine("Press Enter to finish.");
                Console.ReadLine();
            }
        }
    }

    private static string GetConnectionString()
        // To avoid storing the sourceConnection string in your code,
        // you can retrieve it from a configuration file.
    {
        return "Data Source=(local); " +
            " Integrated Security=true;" +
            "Initial Catalog=AdventureWorks;";
    }
}
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        Dim connectionString As String = GetConnectionString()

        ' Open a connection to the AdventureWorks database.
        Using sourceConnection As SqlConnection = _
           New SqlConnection(connectionString)
            sourceConnection.Open()

            ' Perform an initial count on the destination table.
            Dim commandRowCount As New SqlCommand( _
            "SELECT COUNT(*) FROM dbo.BulkCopyDemoMatchingColumns;", _
                sourceConnection)
            Dim countStart As Long = _
               System.Convert.ToInt32(commandRowCount.ExecuteScalar())
            Console.WriteLine("Starting row count = {0}", countStart)

            ' Get data from the source table as a SqlDataReader.
            Dim commandSourceData As New SqlCommand( _
               "SELECT ProductID, Name, ProductNumber " & _
               "FROM Production.Product;", sourceConnection)
            Dim reader As SqlDataReader = commandSourceData.ExecuteReader

            ' Open the destination connection. In the real world you would 
            ' not use SqlBulkCopy to move data from one table to the other   
            ' in the same database. This is for demonstration purposes only.
            Using destinationConnection As SqlConnection = _
                New SqlConnection(connectionString)
                destinationConnection.Open()

                ' Set up the bulk copy object. 
                ' The column positions in the source data reader 
                ' match the column positions in the destination table, 
                ' so there is no need to map columns.
                Using bulkCopy As SqlBulkCopy = _
                  New SqlBulkCopy(destinationConnection)
                    bulkCopy.DestinationTableName = _
                    "dbo.BulkCopyDemoMatchingColumns"

                    Try
                        ' Write from the source to the destination.
                        bulkCopy.WriteToServer(reader)

                    Catch ex As Exception
                        Console.WriteLine(ex.Message)

                    Finally
                        ' Close the SqlDataReader. The SqlBulkCopy
                        ' object is automatically closed at the end
                        ' of the Using block.
                        reader.Close()
                    End Try
                End Using

                ' Perform a final count on the destination table
                ' to see how many rows were added.
                Dim countEnd As Long = _
                    System.Convert.ToInt32(commandRowCount.ExecuteScalar())
                Console.WriteLine("Ending row count = {0}", countEnd)
                Console.WriteLine("{0} rows were added.", countEnd - countStart)

                Console.WriteLine("Press Enter to finish.")
                Console.ReadLine()
            End Using
        End Using
    End Sub

    Private Function GetConnectionString() As String
        ' To avoid storing the sourceConnection string in your code, 
        ' you can retrieve it from a configuration file. 
        Return "Data Source=(local);" & _
            "Integrated Security=true;" & _
            "Initial Catalog=AdventureWorks;"
    End Function
End Module

설명

instance 초기화될 때 SqlBulkCopy 연결이 이미 열려 있으므로 instance 닫힌 후에도 SqlBulkCopy 연결이 열린 상태로 유지됩니다.

인수가 connection null이면 이 ArgumentNullException throw됩니다.

추가 정보

적용 대상

SqlBulkCopy(String)

제공된 connectionString에 따라 SqlConnection의 새 인스턴스를 초기화하고 엽니다. 생성자는 SqlConnection을 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다.

public:
 SqlBulkCopy(System::String ^ connectionString);
public SqlBulkCopy (string connectionString);
new System.Data.SqlClient.SqlBulkCopy : string -> System.Data.SqlClient.SqlBulkCopy
Public Sub New (connectionString As String)

매개 변수

connectionString
String

SqlBulkCopy 인스턴스에서 사용하기 위해 열리는 연결을 정의하는 문자열입니다. 연결 문자열에서 Integrated Security = true를 사용 중이 아니면 SqlBulkCopy(SqlConnection) 또는 SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)SqlCredential을 사용하여 연결 문자열에서 사용자 ID와 암호를 텍스트로 지정할 때보다 사용자 ID와 암호를 보다 안전하게 전달할 수 있습니다.

예제

다음 콘솔 애플리케이션에는 문자열로 지정 된 연결을 사용 하 여 데이터 대량 로드 하는 방법을 보여 줍니다. instance 닫히면 연결이 SqlBulkCopy 자동으로 닫힙니다.

이 예제에서 원본 데이터는 먼저 SQL Server 테이블에서 SqlDataReader instance 읽습니다. 원본 데이터는 SQL Server 위치할 필요가 없습니다. 에 읽 IDataReader 거나 에 로드할 수 있는 데이터 원본을 DataTable사용할 수 있습니다.

중요

이 샘플은 가져올 대량 복사 샘플 설정에 설명된 대로 작업 테이블을 만들지 않은 경우 실행되지 않습니다. 이 코드는 SqlBulkCopy를 사용하는 구문을 보여 주는 용도로 제공됩니다. 원본 테이블과 대상 테이블이 동일한 SQL Server instance 있는 경우 Transact-SQL INSERT ... SELECT 문을 사용하여 데이터를 복사하는 것이 더 쉽고 빠릅니다.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = GetConnectionString();
        // Open a sourceConnection to the AdventureWorks database.
        using (SqlConnection sourceConnection =
                   new SqlConnection(connectionString))
        {
            sourceConnection.Open();

            // Perform an initial count on the destination table.
            SqlCommand commandRowCount = new SqlCommand(
                "SELECT COUNT(*) FROM " +
                "dbo.BulkCopyDemoMatchingColumns;",
                sourceConnection);
            long countStart = System.Convert.ToInt32(
                commandRowCount.ExecuteScalar());
            Console.WriteLine("Starting row count = {0}", countStart);

            // Get data from the source table as a SqlDataReader.
            SqlCommand commandSourceData = new SqlCommand(
                "SELECT ProductID, Name, " +
                "ProductNumber " +
                "FROM Production.Product;", sourceConnection);
            SqlDataReader reader =
                commandSourceData.ExecuteReader();

            // Set up the bulk copy object using a connection string.
            // In the real world you would not use SqlBulkCopy to move
            // data from one table to the other in the same database.
            using (SqlBulkCopy bulkCopy =
                       new SqlBulkCopy(connectionString))
            {
                bulkCopy.DestinationTableName =
                    "dbo.BulkCopyDemoMatchingColumns";

                try
                {
                    // Write from the source to the destination.
                    bulkCopy.WriteToServer(reader);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    // Close the SqlDataReader. The SqlBulkCopy
                    // object is automatically closed at the end
                    // of the using block.
                    reader.Close();
                }
            }

            // Perform a final count on the destination
            // table to see how many rows were added.
            long countEnd = System.Convert.ToInt32(
                commandRowCount.ExecuteScalar());
            Console.WriteLine("Ending row count = {0}", countEnd);
            Console.WriteLine("{0} rows were added.", countEnd - countStart);
            Console.WriteLine("Press Enter to finish.");
            Console.ReadLine();
        }
    }

    private static string GetConnectionString()
        // To avoid storing the sourceConnection string in your code,
        // you can retrieve it from a configuration file.
    {
        return "Data Source=(local); " +
            " Integrated Security=true;" +
            "Initial Catalog=AdventureWorks;";
    }
}
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        Dim connectionString As String = GetConnectionString()

        ' Open a connection to the AdventureWorks database.
        Using sourceConnection As SqlConnection = _
           New SqlConnection(connectionString)
            sourceConnection.Open()

            ' Perform an initial count on the destination table.
            Dim commandRowCount As New SqlCommand( _
            "SELECT COUNT(*) FROM dbo.BulkCopyDemoMatchingColumns;", _
                sourceConnection)
            Dim countStart As Long = _
               System.Convert.ToInt32(commandRowCount.ExecuteScalar())
            Console.WriteLine("Starting row count = {0}", countStart)

            ' Get data from the source table as a SqlDataReader.
            Dim commandSourceData As SqlCommand = New SqlCommand( _
               "SELECT ProductID, Name, ProductNumber " & _
               "FROM Production.Product;", sourceConnection)
            Dim reader As SqlDataReader = commandSourceData.ExecuteReader

            ' Set up the bulk copy object using a connection string. 
            ' In the real world you would not use SqlBulkCopy to move
            ' data from one table to the other in the same database.
            Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(connectionString)
                bulkCopy.DestinationTableName = _
                "dbo.BulkCopyDemoMatchingColumns"

                Try
                    ' Write from the source to the destination.
                    bulkCopy.WriteToServer(reader)

                Catch ex As Exception
                    Console.WriteLine(ex.Message)

                Finally
                    ' Close the SqlDataReader. The SqlBulkCopy
                    ' object is automatically closed at the end
                    ' of the Using block.
                    reader.Close()
                End Try
            End Using

            ' Perform a final count on the destination table
            ' to see how many rows were added.
            Dim countEnd As Long = _
                System.Convert.ToInt32(commandRowCount.ExecuteScalar())
            Console.WriteLine("Ending row count = {0}", countEnd)
            Console.WriteLine("{0} rows were added.", countEnd - countStart)

            Console.WriteLine("Press Enter to finish.")
            Console.ReadLine()
        End Using
    End Sub

    Private Function GetConnectionString() As String
        ' To avoid storing the sourceConnection string in your code, 
        ' you can retrieve it from a configuration file. 
        Return "Data Source=(local);" & _
            "Integrated Security=true;" & _
            "Initial Catalog=AdventureWorks;"
    End Function
End Module

설명

대량 복사 작업이 끝나면 연결이 자동으로 닫힙니다.

가 null이면 connectionStringArgumentNullException throw됩니다. 가 빈 문자열이면 connectionStringArgumentException throw됩니다.

추가 정보

적용 대상

SqlBulkCopy(String, SqlBulkCopyOptions)

제공된 connectionString에 따라 SqlConnection의 새 인스턴스를 초기화하고 엽니다. 이 생성자는 SqlConnection을 사용하여 SqlBulkCopy 클래스의 새 인스턴스를 초기화합니다. SqlConnection 인스턴스는 copyOptions 매개 변수에 제공된 옵션에 따라 작동합니다.

public:
 SqlBulkCopy(System::String ^ connectionString, System::Data::SqlClient::SqlBulkCopyOptions copyOptions);
public SqlBulkCopy (string connectionString, System.Data.SqlClient.SqlBulkCopyOptions copyOptions);
new System.Data.SqlClient.SqlBulkCopy : string * System.Data.SqlClient.SqlBulkCopyOptions -> System.Data.SqlClient.SqlBulkCopy
Public Sub New (connectionString As String, copyOptions As SqlBulkCopyOptions)

매개 변수

connectionString
String

SqlBulkCopy 인스턴스에서 사용하기 위해 열리는 연결을 정의하는 문자열입니다. 연결 문자열에서 Integrated Security = true를 사용 중이 아니면 SqlBulkCopy(SqlConnection) 또는 SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)SqlCredential을 사용하여 연결 문자열에서 사용자 ID와 암호를 텍스트로 지정할 때보다 사용자 ID와 암호를 보다 안전하게 전달할 수 있습니다.

copyOptions
SqlBulkCopyOptions

대상 테이블에 복사되는 데이터 소스 행을 결정하는 SqlBulkCopyOptions 열거형의 값 조합입니다.

예제

다음 콘솔 애플리케이션에는 문자열로 지정 된 연결을 사용 하 여 대량 로드를 수행 하는 방법을 보여 줍니다. 대상 테이블을 로드할 때 원본 테이블의 ID 열에 있는 값을 사용하도록 옵션이 설정됩니다. 이 예제에서 원본 데이터는 먼저 SQL Server 테이블에서 SqlDataReader instance 읽습니다. 원본 테이블과 대상 테이블에는 각각 ID 열이 포함됩니다. 기본적으로 ID 열의 새 값은 추가된 각 행의 대상 테이블에 생성됩니다. 이 예제에서는 대량 로드 프로세스가 원본 테이블의 ID 값을 대신 사용하도록 강제하는 연결이 열릴 때 옵션이 설정됩니다. 옵션이 대량 로드의 작동 방식을 변경하는 방법을 확인하려면 dbo를 사용하여 샘플을 실행합니다 . BulkCopyDemoMatchingColumns 테이블이 비어 있습니다 . 모든 행은 원본에서 로드됩니다. 그런 다음 테이블을 비우지 않고 샘플을 다시 실행합니다. 예외가 throw되고 코드는 기본 키 제약 조건 위반으로 인해 행이 추가되지 않았음을 알리는 메시지를 콘솔에 씁니다.

중요

이 샘플은 가져올 대량 복사 샘플 설정에 설명된 대로 작업 테이블을 만들지 않은 경우 실행되지 않습니다. 이 코드는 SqlBulkCopy를 사용하는 구문을 보여 주는 용도로 제공됩니다. 원본 테이블과 대상 테이블이 동일한 SQL Server instance 있는 경우 Transact-SQL INSERT ... SELECT 문을 사용하여 데이터를 복사하는 것이 더 쉽고 빠릅니다.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        string connectionString = GetConnectionString();
        // Open a sourceConnection to the AdventureWorks database.
        using (SqlConnection sourceConnection =
                   new SqlConnection(connectionString))
        {
            sourceConnection.Open();

            // Perform an initial count on the destination table.
            SqlCommand commandRowCount = new SqlCommand(
                "SELECT COUNT(*) FROM " +
                "dbo.BulkCopyDemoMatchingColumns;",
                sourceConnection);
            long countStart = System.Convert.ToInt32(
                commandRowCount.ExecuteScalar());
            Console.WriteLine("Starting row count = {0}", countStart);

            // Get data from the source table as a SqlDataReader.
            SqlCommand commandSourceData = new SqlCommand(
                "SELECT ProductID, Name, " +
                "ProductNumber " +
                "FROM Production.Product;", sourceConnection);
            SqlDataReader reader =
                commandSourceData.ExecuteReader();

            // Create the SqlBulkCopy object using a connection string
            // and the KeepIdentity option.
            // In the real world you would not use SqlBulkCopy to move
            // data from one table to the other in the same database.
            using (SqlBulkCopy bulkCopy =
                new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity))
            {
                bulkCopy.DestinationTableName =
                    "dbo.BulkCopyDemoMatchingColumns";

                try
                {
                    // Write from the source to the destination.
                    bulkCopy.WriteToServer(reader);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    // Close the SqlDataReader. The SqlBulkCopy
                    // object is automatically closed at the end
                    // of the using block.
                    reader.Close();
                }
            }

            // Perform a final count on the destination
            // table to see how many rows were added.
            long countEnd = System.Convert.ToInt32(
                commandRowCount.ExecuteScalar());
            Console.WriteLine("Ending row count = {0}", countEnd);
            Console.WriteLine("{0} rows were added.", countEnd - countStart);
            Console.WriteLine("Press Enter to finish.");
            Console.ReadLine();
        }
    }

    private static string GetConnectionString()
        // To avoid storing the sourceConnection string in your code,
        // you can retrieve it from a configuration file.
    {
        return "Data Source=(local); " +
            " Integrated Security=true;" +
            "Initial Catalog=AdventureWorks;";
    }
}
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        Dim connectionString As String = GetConnectionString()

        ' Open a connection to the AdventureWorks database.
        Using sourceConnection As SqlConnection = _
           New SqlConnection(connectionString)
            sourceConnection.Open()

            ' Perform an initial count on the destination table.
            Dim commandRowCount As New SqlCommand( _
            "SELECT COUNT(*) FROM dbo.BulkCopyDemoMatchingColumns;", _
                sourceConnection)
            Dim countStart As Long = _
               System.Convert.ToInt32(commandRowCount.ExecuteScalar())
            Console.WriteLine("Starting row count = {0}", countStart)

            ' Get data from the source table as a SqlDataReader.
            Dim commandSourceData As SqlCommand = New SqlCommand( _
               "SELECT ProductID, Name, ProductNumber " & _
               "FROM Production.Product;", sourceConnection)
            Dim reader As SqlDataReader = commandSourceData.ExecuteReader

            ' Create the SqlBulkCopy object using a connection string 
            ' and the KeepIdentity option. 
            ' In the real world you would not use SqlBulkCopy to move
            ' data from one table to the other in the same database.
            Using bulkCopy As SqlBulkCopy = _
              New SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity)
                bulkCopy.DestinationTableName = "dbo.BulkCopyDemoMatchingColumns"

                Try
                    ' Write from the source to the destination.
                    bulkCopy.WriteToServer(reader)

                Catch ex As Exception
                    Console.WriteLine(ex.Message)

                    Finally
                        ' Close the SqlDataReader. The SqlBulkCopy
                        ' object is automatically closed at the end
                        ' of the Using block.
                        reader.Close()
                End Try
            End Using

            ' Perform a final count on the destination table
            ' to see how many rows were added.
            Dim countEnd As Long = _
                System.Convert.ToInt32(commandRowCount.ExecuteScalar())
            Console.WriteLine("Ending row count = {0}", countEnd)
            Console.WriteLine("{0} rows were added.", countEnd - countStart)

            Console.WriteLine("Press Enter to finish.")
            Console.ReadLine()
        End Using
    End Sub

    Private Function GetConnectionString() As String
        ' To avoid storing the sourceConnection string in your code, 
        ' you can retrieve it from a configuration file. 
        Return "Data Source=(local);" & _
            "Integrated Security=true;" & _
            "Initial Catalog=AdventureWorks;"
    End Function
End Module

설명

항목의 모든 대량 복사 옵션 SqlBulkCopyOptions 에 대한 자세한 정보를 얻을 수 있습니다.

추가 정보

적용 대상

SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)

제공된 SqlBulkCopy의 이미 열려 있는 인스턴스를 사용하여 SqlConnection 클래스의 새 인스턴스를 초기화합니다. SqlBulkCopy 인스턴스는 copyOptions 매개 변수에 제공된 옵션에 따라 작동합니다. 제공된 SqlTransaction이 null이 아니면 복사 작업이 해당 트랜잭션 내에서 수행됩니다.

public:
 SqlBulkCopy(System::Data::SqlClient::SqlConnection ^ connection, System::Data::SqlClient::SqlBulkCopyOptions copyOptions, System::Data::SqlClient::SqlTransaction ^ externalTransaction);
public SqlBulkCopy (System.Data.SqlClient.SqlConnection connection, System.Data.SqlClient.SqlBulkCopyOptions copyOptions, System.Data.SqlClient.SqlTransaction externalTransaction);
new System.Data.SqlClient.SqlBulkCopy : System.Data.SqlClient.SqlConnection * System.Data.SqlClient.SqlBulkCopyOptions * System.Data.SqlClient.SqlTransaction -> System.Data.SqlClient.SqlBulkCopy
Public Sub New (connection As SqlConnection, copyOptions As SqlBulkCopyOptions, externalTransaction As SqlTransaction)

매개 변수

connection
SqlConnection

대량 복사 작업을 수행하는 데 사용할 이미 열려 있는 SqlConnection 인스턴스입니다. 연결 문자열이 Integrated Security = true를 사용하지 않는 경우 SqlCredential 을 사용하여 사용자 ID와 암호를 연결 문자열에 텍스트로 지정하는 것보다 더 안전하게 사용자 ID와 암호를 제공할 수 있습니다.

copyOptions
SqlBulkCopyOptions

대상 테이블에 복사되는 데이터 소스 행을 결정하는 SqlBulkCopyOptions 열거형의 값 조합입니다.

externalTransaction
SqlTransaction

대량 복사 작업이 발생할 기존 SqlTransaction 인스턴스입니다.

설명

옵션이 포함 UseInternalTransaction 되고 인수가 externalTransaction null이 아니면 InvalidArgumentException 이 throw됩니다.

트랜잭션에서 사용하는 SqlBulkCopy 방법을 보여 주는 예제는 트랜잭션 및 대량 복사 작업을 참조하세요.

추가 정보

적용 대상