Class SqlServerBulkInsert
Class for fast data inserting into SQL Server.
Inheritance
Implements
Namespace: Kros.Data.BulkActions.SqlServer
Assembly: Kros.Utils.dll
Syntax
public class SqlServerBulkInsert : IBulkInsert, IDisposable
Constructors
SqlServerBulkInsert(SqlConnection)
Initialize new instance of SqlServerBulkInsert with database connection connection
.
Declaration
public SqlServerBulkInsert(SqlConnection connection)
Parameters
Type | Name | Description |
---|---|---|
System.Data.SqlClient.SqlConnection | connection | Database connection where data will be inserted, connection has to be opened. If transaction is running on connection, contructor with defined external transaction must be used. |
SqlServerBulkInsert(SqlConnection, SqlBulkCopyOptions)
Initialize new instance of SqlServerBulkInsert with database connection connection
and defined options options
.
Declaration
public SqlServerBulkInsert(SqlConnection connection, SqlBulkCopyOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.Data.SqlClient.SqlConnection | connection | Database connection where data will be inserted, connection has to be opened. |
System.Data.SqlClient.SqlBulkCopyOptions | options | Options System.Data.SqlClient.SqlBulkCopyOptions. |
SqlServerBulkInsert(SqlConnection, SqlTransaction)
Initialize new instance of SqlServerBulkInsert with database connection connection
and external transaction externalTransaction
.
Declaration
public SqlServerBulkInsert(SqlConnection connection, SqlTransaction externalTransaction)
Parameters
Type | Name | Description |
---|---|---|
System.Data.SqlClient.SqlConnection | connection | Database connection where data will be inserted, connection has to be opened.
If transaction is running on connection, transaction has to be defined in |
System.Data.SqlClient.SqlTransaction | externalTransaction | External transaction, in which bulk insert is executed. |
SqlServerBulkInsert(SqlConnection, SqlTransaction, SqlBulkCopyOptions)
Initialize new instance of SqlServerBulkInsert with database connection connection
,
external transaction externalTransaction
and defined options options
.
Declaration
public SqlServerBulkInsert(SqlConnection connection, SqlTransaction externalTransaction, SqlBulkCopyOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.Data.SqlClient.SqlConnection | connection | Database connection where data will be inserted, connection has to be opened.
If transaction is running on connection, transaction has to be defined in |
System.Data.SqlClient.SqlTransaction | externalTransaction | External transaction, in which bulk insert is executed. |
System.Data.SqlClient.SqlBulkCopyOptions | options | Options System.Data.SqlClient.SqlBulkCopyOptions. |
SqlServerBulkInsert(String)
Initialize new instance of SqlServerBulkInsert with connectionString
.
Declaration
public SqlServerBulkInsert(string connectionString)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString | Connection string for database connection. |
SqlServerBulkInsert(String, SqlBulkCopyOptions)
Initialize new instance of SqlServerBulkInsert with connectionString
and defined options options
.
Declaration
public SqlServerBulkInsert(string connectionString, SqlBulkCopyOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString | Connection string for database connection. |
System.Data.SqlClient.SqlBulkCopyOptions | options | Options System.Data.SqlClient.SqlBulkCopyOptions. |
Properties
BatchSize
Row count for batch sent to database. If 0, batch size is not limited.
Declaration
public int BatchSize { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Value is negative. |
BulkCopyOptions
Options BulkCopyOptions for internal instance of System.Data.SqlClient.SqlBulkCopy.
Declaration
public SqlBulkCopyOptions BulkCopyOptions { get; }
Property Value
Type | Description |
---|---|
System.Data.SqlClient.SqlBulkCopyOptions |
BulkInsertTimeout
Timeout for BulkInsert operation. If 0, duration of operation is not limited.
Declaration
public int BulkInsertTimeout { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Value is negative. |
DefaultBulkCopyOptions
Default System.Data.SqlClient.SqlBulkCopyOptions for internal instance of System.Data.SqlClient.SqlBulkCopy,
if external transaction is not used.
Value is SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.UseInternalTransaction
.
Declaration
public static SqlBulkCopyOptions DefaultBulkCopyOptions { get; }
Property Value
Type | Description |
---|---|
System.Data.SqlClient.SqlBulkCopyOptions |
DefaultBulkCopyOptionsExternalTransaction
Default System.Data.SqlClient.SqlBulkCopyOptions for internal instance of System.Data.SqlClient.SqlBulkCopy,
if external transaction is used.
Value is SqlBulkCopyOptions.TableLock
.
Declaration
public static SqlBulkCopyOptions DefaultBulkCopyOptionsExternalTransaction { get; }
Property Value
Type | Description |
---|---|
System.Data.SqlClient.SqlBulkCopyOptions |
DestinationTableName
Destination table name in database.
Declaration
public string DestinationTableName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ExternalTransaction
External transaction, in which bulk insert is executed.
Declaration
public SqlTransaction ExternalTransaction { get; }
Property Value
Type | Description |
---|---|
System.Data.SqlClient.SqlTransaction |
Methods
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Insert(IBulkActionDataReader)
Declaration
public void Insert(IBulkActionDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
IBulkActionDataReader | reader |
Insert(DataTable)
Declaration
public void Insert(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DataTable | table |
Insert(IDataReader)
Declaration
public void Insert(IDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Data.IDataReader | reader |
InsertAsync(IBulkActionDataReader)
Declaration
public Task InsertAsync(IBulkActionDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
IBulkActionDataReader | reader |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
InsertAsync(DataTable)
Declaration
public Task InsertAsync(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DataTable | table |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
InsertAsync(IDataReader)
Declaration
public Task InsertAsync(IDataReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Data.IDataReader | reader |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |