SqlBulkCopy Constructors

Definitie

Initialiseert een nieuw exemplaar van de SqlBulkCopy klasse.

Overloads

Name Description
SqlBulkCopy(SqlConnection)

Initialiseert een nieuw exemplaar van de SqlBulkCopy klasse met behulp van de opgegeven open instantie van SqlConnection.

SqlBulkCopy(String)

Initialiseert en opent een nieuw exemplaar van SqlConnection op basis van de opgegeven connectionString. De constructor gebruikt de SqlConnection opdracht om een nieuw exemplaar van de SqlBulkCopy klasse te initialiseren.

SqlBulkCopy(String, SqlBulkCopyOptions)

Initialiseert en opent een nieuw exemplaar van SqlConnection op basis van de opgegeven connectionString. De constructor gebruikt dit SqlConnection om een nieuw exemplaar van de SqlBulkCopy klasse te initialiseren. Het SqlConnection exemplaar gedraagt zich volgens de opties die zijn opgegeven in de copyOptions parameter.

SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)

Initialiseert een nieuw exemplaar van de SqlBulkCopy klasse met behulp van de opgegeven bestaande open instantie van SqlConnection. Het SqlBulkCopy exemplaar gedraagt zich volgens de opties die zijn opgegeven in de copyOptions parameter. Als er een niet-null-waarde SqlTransaction wordt opgegeven, worden de kopieerbewerkingen binnen die transactie uitgevoerd.

SqlBulkCopy(SqlConnection)

Initialiseert een nieuw exemplaar van de SqlBulkCopy klasse met behulp van de opgegeven open instantie van 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)

Parameters

connection
SqlConnection

Het reeds geopende SqlConnection exemplaar dat wordt gebruikt om de bulkkopiebewerking uit te voeren. Als uw verbindingsreeks Integrated Security = true niet gebruikt, kunt u SqlCredential gebruiken om de gebruikers-id en het wachtwoord veiliger door te geven dan door de gebruikers-id en het wachtwoord op te geven als tekst in de verbindingsreeks.

Voorbeelden

In de volgende consoletoepassing ziet u hoe u gegevens bulksgewijs laadt met behulp van een verbinding die al is geopend. In dit voorbeeld wordt er een SqlDataReader gebruikt voor het kopiëren van gegevens uit de tabel Production.Product in de SQL Server AdventureWorks-database naar een vergelijkbare tabel in dezelfde database. Dit voorbeeld is alleen bedoeld voor demonstratiedoeleinden. U kunt gegevens niet SqlBulkCopy van de ene tabel naar de andere verplaatsen in dezelfde database in een productietoepassing. Houd er rekening mee dat de brongegevens zich niet op SQL Server bevinden; u kunt elke gegevensbron gebruiken die kan worden gelezen naar een IDataReader of geladen in een DataTable.

Important

Dit voorbeeld wordt niet uitgevoerd tenzij u de werktabellen hebt gemaakt, zoals beschreven in Bulk Copy Voorbeeldconfiguratie. Deze code wordt verstrekt om alleen de syntaxis voor het gebruik van SqlBulkCopy te demonstreren. Als de bron- en doeltabellen zich in hetzelfde SQL Server exemplaar bevinden, is het eenvoudiger en sneller om een Transact-SQL INSERT ... SELECT-instructie te gebruiken om de gegevens te kopiëren.

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

Opmerkingen

Omdat de verbinding al is geopend wanneer het SqlBulkCopy exemplaar wordt geïnitialiseerd, blijft de verbinding geopend nadat het SqlBulkCopy exemplaar is gesloten.

Als het connection argument null is, wordt er een ArgumentNullException gegenereerd.

Zie ook

Van toepassing op

SqlBulkCopy(String)

Initialiseert en opent een nieuw exemplaar van SqlConnection op basis van de opgegeven connectionString. De constructor gebruikt de SqlConnection opdracht om een nieuw exemplaar van de SqlBulkCopy klasse te initialiseren.

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)

Parameters

connectionString
String

De tekenreeks die de verbinding definieert die wordt geopend voor gebruik door het SqlBulkCopy exemplaar. Als uw verbindingsreeks geen gebruik maakt van Integrated Security = true, kunt u SqlBulkCopy(SqlConnection) of SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction) en SqlCredential gebruiken om de gebruikers-id en het wachtwoord veiliger door te geven dan door de gebruikers-id en het wachtwoord op te geven als tekst in de verbindingsreeks.

Voorbeelden

In de volgende consoletoepassing ziet u hoe u gegevens bulksgewijs laadt met behulp van een verbinding die is opgegeven als een tekenreeks. De verbinding wordt automatisch gesloten wanneer het SqlBulkCopy exemplaar wordt gesloten.

In dit voorbeeld worden de brongegevens eerst gelezen uit een SQL Server tabel naar een SqlDataReader-exemplaar. De brongegevens hoeven zich niet op SQL Server te bevinden; u kunt elke gegevensbron gebruiken die kan worden gelezen naar een IDataReader of geladen in een DataTable.

Important

Dit voorbeeld wordt niet uitgevoerd tenzij u de werktabellen hebt gemaakt, zoals beschreven in Bulk Copy Voorbeeldconfiguratie. Deze code wordt verstrekt om alleen de syntaxis voor het gebruik van SqlBulkCopy te demonstreren. Als de bron- en doeltabellen zich in hetzelfde SQL Server exemplaar bevinden, is het eenvoudiger en sneller om een Transact-SQL INSERT ... SELECT-instructie te gebruiken om de gegevens te kopiëren.

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

Opmerkingen

De verbinding wordt automatisch gesloten aan het einde van de bulkkopiebewerking.

Als connectionString null is, wordt er een ArgumentNullException gegenereerd. Als connectionString dit een lege tekenreeks is, wordt er een ArgumentException gegenereerd.

Zie ook

Van toepassing op

SqlBulkCopy(String, SqlBulkCopyOptions)

Initialiseert en opent een nieuw exemplaar van SqlConnection op basis van de opgegeven connectionString. De constructor gebruikt dit SqlConnection om een nieuw exemplaar van de SqlBulkCopy klasse te initialiseren. Het SqlConnection exemplaar gedraagt zich volgens de opties die zijn opgegeven in de copyOptions parameter.

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)

Parameters

connectionString
String

De tekenreeks die de verbinding definieert die wordt geopend voor gebruik door het SqlBulkCopy exemplaar. Als uw verbindingsreeks geen gebruik maakt van Integrated Security = true, kunt u SqlBulkCopy(SqlConnection) of SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction) en SqlCredential gebruiken om de gebruikers-id en het wachtwoord veiliger door te geven dan door de gebruikers-id en het wachtwoord op te geven als tekst in de verbindingsreeks.

copyOptions
SqlBulkCopyOptions

Een combinatie van waarden uit de SqlBulkCopyOptions opsomming die bepaalt welke gegevensbronrijen naar de doeltabel worden gekopieerd.

Voorbeelden

De volgende consoletoepassing laat zien hoe u een bulksgewijs laadt met behulp van een verbinding die is opgegeven als een tekenreeks. Er is een optie ingesteld om de waarde in de identiteitskolom van de brontabel te gebruiken wanneer u de doeltabel laadt. In dit voorbeeld worden de brongegevens eerst gelezen uit een SQL Server tabel naar een SqlDataReader-exemplaar. De brontabel en doeltabel bevatten elk een identiteitskolom. Standaard wordt een nieuwe waarde voor de kolom Identiteit gegenereerd in de doeltabel voor elke toegevoegde rij. In dit voorbeeld wordt een optie ingesteld wanneer de verbinding wordt geopend, waardoor het bulksgewijs ladenproces in plaats daarvan de identiteitswaarden uit de brontabel kan gebruiken. Als u wilt zien hoe de optie de manier wijzigt waarop de bulkbelasting werkt, voert u het voorbeeld uit met de dbo. De tabel BulkCopyDemoMatchingColumns leeg. Alle rijen worden uit de bron geladen. Voer vervolgens het voorbeeld opnieuw uit zonder de tabel leeg te maken. Er wordt een uitzondering gegenereerd en de code schrijft een bericht naar de console met de melding dat rijen niet zijn toegevoegd vanwege schendingen van de primaire sleutelbeperking.

Important

Dit voorbeeld wordt niet uitgevoerd tenzij u de werktabellen hebt gemaakt, zoals beschreven in Bulk Copy Voorbeeldconfiguratie. Deze code wordt verstrekt om alleen de syntaxis voor het gebruik van SqlBulkCopy te demonstreren. Als de bron- en doeltabellen zich in hetzelfde SQL Server exemplaar bevinden, is het eenvoudiger en sneller om een Transact-SQL INSERT ... SELECT-instructie te gebruiken om de gegevens te kopiëren.

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

Opmerkingen

U kunt gedetailleerde informatie verkrijgen over alle opties voor bulkkopie in het SqlBulkCopyOptions onderwerp.

Zie ook

Van toepassing op

SqlBulkCopy(SqlConnection, SqlBulkCopyOptions, SqlTransaction)

Initialiseert een nieuw exemplaar van de SqlBulkCopy klasse met behulp van de opgegeven bestaande open instantie van SqlConnection. Het SqlBulkCopy exemplaar gedraagt zich volgens de opties die zijn opgegeven in de copyOptions parameter. Als er een niet-null-waarde SqlTransaction wordt opgegeven, worden de kopieerbewerkingen binnen die transactie uitgevoerd.

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)

Parameters

connection
SqlConnection

Het reeds geopende SqlConnection exemplaar dat wordt gebruikt om de bulkkopie uit te voeren. Als uw verbindingsreeks Integrated Security = true niet gebruikt, kunt u SqlCredential gebruiken om de gebruikers-id en het wachtwoord veiliger door te geven dan door de gebruikers-id en het wachtwoord op te geven als tekst in de verbindingsreeks.

copyOptions
SqlBulkCopyOptions

Een combinatie van waarden uit de SqlBulkCopyOptions opsomming die bepaalt welke gegevensbronrijen naar de doeltabel worden gekopieerd.

externalTransaction
SqlTransaction

Een bestaand SqlTransaction exemplaar waaronder de bulkkopie plaatsvindt.

Opmerkingen

Als opties zijn opgenomen UseInternalTransaction en het externalTransaction argument niet null is, wordt er een InvalidArgumentException gegenereerd.

Zie Transactie- en bulkkopiebewerkingen voor voorbeelden die laten zien hoe u een transactie gebruiktSqlBulkCopy.

Zie ook

Van toepassing op