sqlbulkcopy

How to prevent duplicate records being inserted with SqlBulkCopy when there is no primary key

試著忘記壹切 提交于 2019-11-27 22:07:17
I receive a daily XML file that contains thousands of records, each being a business transaction that I need to store in an internal database for use in reporting and billing. I was under the impression that each day's file contained only unique records, but have discovered that my definition of unique is not exactly the same as the provider's. The current application that imports this data is a C#.Net 3.5 console application, it does so using SqlBulkCopy into a MS SQL Server 2008 database table where the columns exactly match the structure of the XML records. Each record has just over 100

SqlBulkCopy and Entity Framework

假装没事ソ 提交于 2019-11-27 20:11:14
My current project consists of 3 standard layers: data, business, and presentation. I would like to use data entities for all my data access needs. Part of the functionality of the app will that it will need to copy all data within a flat file into a database. The file is not so big so I can use SqlBulkCopy. I have found several articles regarding the usage of SqlBulkCopy class in .NET. However, all the articles are using DataTables to move data back and forth. Is there a way to use data entities along with SqlBulkCopy or will I have to use DataTables? You'll need to convert the Entities to a

Timeout expired with SqlBulkCopy

二次信任 提交于 2019-11-27 17:27:09
问题 I'm using SqlBulkCopy to restore tables from xml backups. One of the table backup is ~200MB large and has a lot of records. I'm having error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 回答1: You probably need to increase the timeout. Try increasing the value of sqlBulkCopy.BulkCopyTimeout from the default which is 30 seconds. 回答2: There are two ways to fix this error: Increase Timeout by default it is 30 second and 0 means

SqlBulkCopy - The given value of type String from the data source cannot be converted to type money of the specified target column

帅比萌擦擦* 提交于 2019-11-27 12:19:16
I'm getting this exception when trying to do an SqlBulkCopy from a DataTable. Error Message: The given value of type String from the data source cannot be converted to type money of the specified target column. Target Site: System.Object ConvertValue(System.Object, System.Data.SqlClient._SqlMetaData, Boolean, Boolean ByRef, Boolean ByRef) I understand what the error is saying, but how I can I get more information, such as the row/field this is happening on? The datatable is populated by a 3rd party and can contain up to 200 columns and up to 10k rows. The columns that are returned depend on

SQLBulkCopy Row Count When Complete

落爺英雄遲暮 提交于 2019-11-27 12:11:26
问题 I am using SQLBulkCopy to move large amounts of data. I implemented the notification event to notify me every time a certain number of rows have been processed, but the OnSqlRowsCopied event does not fire when the job is completed. How do I get the total number of rows copied when the SQLBulkCopy writetoserver completes? 回答1: I think you have to run a COUNT() query on the table after finishing, as in the MSDN example here. Other than that, can't you tell up front? e.g. if you're passing a

SQL Bulkcopy YYYYMMDD problem

自闭症网瘾萝莉.ら 提交于 2019-11-27 08:19:02
问题 I have a String to Date conversion problem using SQL Bulkcopy in asp.net 3.5 with C# I read a large CSV file (with CSV reader). One of the strings read should be loaded into a SQL server 2008 Date column. If the textfile contains for example the string '2010-12-31', SQL Bulkcopy loads it without any problems into the Date column. However, if the string is '20101231', I get an error: The given value of type String from the data source cannot be converted to type date of the specified target

Using SQLBulkCopy to Insert/Update database

柔情痞子 提交于 2019-11-27 05:59:45
问题 I have a datatable with the records.I'm inserting records into Sql table using SqlBulkCopy.It works fine.Next time when get the datatable with same records with few changed values SqlBulkCopy is inserting another set of records without updating the previous details.How can I update the Sql table using SqlBulkCopy ?? Please help. Thanks, Vix 回答1: SqlBulkCopy is only used for inserting records, not updating them as explained here. You'd need to use a different technique to do bulk updates. e.g.

C# Bulk Insert SQLBulkCopy - Update if Exists [duplicate]

梦想的初衷 提交于 2019-11-27 05:33:59
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Any way to SQLBulkCopy “insert or update if exists”? I am using SQLBulkCopy to insert Bulk records How can I perform on update (rather than an insert) on records that already exist? Is this possible with SQLBulkCopy ? This is my code for SQLBulkCopy using (var bulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, SqlBulkCopyOptions.KeepNulls & SqlBulkCopyOptions

SqlBulkCopy Error handling / continue on error

岁酱吖の 提交于 2019-11-27 04:34:43
问题 I am trying to insert huge amount of data into SQL server. My destination table has an unique index called "Hash". I would like to replace my SqlDataAdapter implementation with SqlBulkCopy. In SqlDataAapter there is a property called "ContinueUpdateOnError", when set to true adapter.Update(table) will insert all the rows possible and tag the error rows with RowError property. The question is how can I use SqlBulkCopy to insert data as quickly as possible while keeping track of which rows got

Mapping columns in a DataTable to a SQL table with SqlBulkCopy

允我心安 提交于 2019-11-27 04:30:38
I would like to know how I can map columns in a database table to the datatable in c# before adding the data to the database. using (SqlBulkCopy s = new SqlBulkCopy(conn)) { s.DestinationTableName = destination; s.WriteToServer(Ads_api_ReportData); } StackTrace You probably need some thing like public void BatchBulkCopy(DataTable dataTable, string DestinationTbl, int batchSize) { // Get the DataTable DataTable dtInsertRows = dataTable; using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity)) { sbc.DestinationTableName = DestinationTbl; // Number of records