SqlBulkCopy コンストラクター

定義

SqlBulkCopy クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
SqlBulkCopy(SqlConnection)

SqlBulkCopy の指定されたオープン インスタンスを使用して、SqlConnection クラスの新しいインスタンスを初期化します。

SqlBulkCopy(String)

指定された SqlConnection に基づいて、connectionString の新しいインスタンスを初期化して開きます。 コンストラクターは、SqlConnection を使用して、SqlBulkCopy クラスの新しいインスタンスを初期化します。

SqlBulkCopy(String, SqlBulkCopyOptions)

指定された SqlConnection に基づいて、connectionString の新しいインスタンスを初期化して開きます。 コンストラクターはその SqlConnection を使用して、 SqlBulkCopy クラスの新しいインスタンスを初期化します。 SqlConnection インスタンスは、copyOptions パラメーターで指定されたオプションに従って動作します。

SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)

SqlBulkCopyの指定された既存のオープン インスタンスを使用して、SqlConnection クラスの新しいインスタンスを初期化します。 SqlBulkCopy インスタンスは、copyOptions パラメーターで指定されたオプションに従って動作します。 null 以外の SqlTransaction が指定されている場合、コピー操作はそのトランザクション内で実行されます。

SqlBulkCopy(SqlConnection)

ソース:
System.Data.SqlClient.notsupported.cs

SqlBulkCopy の指定されたオープン インスタンスを使用して、SqlConnection クラスの新しいインスタンスを初期化します。

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に読み込んだりできる任意のデータ ソースを使用できます。

Important

このサンプルは、「バルク コピー サンプルのセットアップ」で説明されているように作業テーブルを作成してからでないと動作しません。 このコードでは、SqlBulkCopy だけを使用した構文について説明します。 ソース テーブルと変換先テーブルが同じ SQL Server インスタンス内にある場合は、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

注釈

SqlBulkCopy インスタンスの初期化時に接続は既に開かれているため、SqlBulkCopy インスタンスを閉じた後も接続は開いたままです。

connection引数が null の場合は、ArgumentNullExceptionがスローされます。

こちらもご覧ください

適用対象

SqlBulkCopy(String)

ソース:
System.Data.SqlClient.notsupported.cs

指定された SqlConnection に基づいて、connectionString の新しいインスタンスを初期化して開きます。 コンストラクターは、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 とパスワードを渡すことができます。

次のコンソール アプリケーションは、文字列として指定された接続を使用してデータを一括読み込みする方法を示しています。 SqlBulkCopy インスタンスが閉じられると、接続は自動的に閉じられます。

この例では、ソース データは最初に SQL Server テーブルから SqlDataReader インスタンスに読み取られます。 ソース データを SQL Server に配置する必要はありません。 IDataReader に読み込んだり、 DataTableに読み込んだりできる任意のデータ ソースを使用できます。

Important

このサンプルは、「バルク コピー サンプルのセットアップ」で説明されているように作業テーブルを作成してからでないと動作しません。 このコードでは、SqlBulkCopy だけを使用した構文について説明します。 ソース テーブルと変換先テーブルが同じ SQL Server インスタンス内にある場合は、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

注釈

接続は、一括コピー操作の最後に自動的に閉じられます。

connectionStringが null の場合は、ArgumentNullExceptionがスローされます。 connectionStringが空の文字列の場合は、ArgumentExceptionがスローされます。

こちらもご覧ください

適用対象

SqlBulkCopy(String, SqlBulkCopyOptions)

ソース:
System.Data.SqlClient.notsupported.cs

指定された SqlConnection に基づいて、connectionString の新しいインスタンスを初期化して開きます。 コンストラクターはその 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 インスタンスに読み取られます。 ソース テーブルと変換先テーブルには、それぞれ ID 列が含まれます。 既定では、追加された各行の宛先テーブルに IDENTITY 列の新しい値が生成されます。 この例では、接続を開いたときにオプションが設定され、一括読み込みプロセスでソース テーブルの ID 値が強制的に使用されます。 一括読み込みの動作方法をオプションで変更する方法を確認するには、dbo を使用してサンプルを実行します 。BulkCopyDemoMatchingColumns テーブルが空です。 すべての行がソースから読み込まれます。 次に、テーブルを空にせずにサンプルをもう一度実行します。 例外がスローされ、主キー制約違反のために行が追加されなかったことを通知するメッセージがコンソールに書き込まれます。

Important

このサンプルは、「バルク コピー サンプルのセットアップ」で説明されているように作業テーブルを作成してからでないと動作しません。 このコードでは、SqlBulkCopy だけを使用した構文について説明します。 ソース テーブルと変換先テーブルが同じ SQL Server インスタンス内にある場合は、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)

ソース:
System.Data.SqlClient.notsupported.cs

SqlBulkCopyの指定された既存のオープン インスタンスを使用して、SqlConnection クラスの新しいインスタンスを初期化します。 SqlBulkCopy インスタンスは、copyOptions パラメーターで指定されたオプションに従って動作します。 null 以外の SqlTransaction が指定されている場合、コピー操作はそのトランザクション内で実行されます。

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 がスローされます。

トランザクションで SqlBulkCopy を使用する方法を示す例については、「 トランザクションおよび一括コピー操作」を参照してください。

こちらもご覧ください

適用対象