sqlbulkcopy

Timeout expired with SqlBulkCopy

这一生的挚爱 提交于 2019-11-29 02:58:02
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. You probably need to increase the timeout. Try increasing the value of sqlBulkCopy.BulkCopyTimeout from the default which is 30 seconds. There are two ways to fix this error: Increase Timeout by default it is 30 second and 0 means infinite. sqlBulkCopy.BulkCopyTimeout = {time in seconds} Decrease BatchSize by default it try to insert all rows

Does SqlBulkCopy automatically start a transaction?

北城以北 提交于 2019-11-28 21:16:50
问题 I am inserting data via SqlBulkCopy like so: public void testBulkInsert(string connection, string table, DataTable dt) { using (SqlConnection con = new SqlConnection(connection)) { con.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con)) { bulkCopy.DestinationTableName = table; bulkCopy.WriteToServer(dt); } } } Will this automatically be wrapped in a SQL transaction so that if something goes wrong half way through the DB will be left in the same state as it was before the bulk insert

SQLBulkCopy Row Count When Complete

烂漫一生 提交于 2019-11-28 19:17:05
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? 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 DataTable to WriteToServer() then you know how many records by doing a .Rows.Count on it. The following hack

SQL Bulkcopy YYYYMMDD problem

拜拜、爱过 提交于 2019-11-28 14:14:22
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 column The file contains 80 million records so I cannot create a datatable.... SqlBulkcopy

Using SQLBulkCopy to Insert/Update database

风格不统一 提交于 2019-11-28 11:12:42
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 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. you could SqlBulkCopy into a staging table, then run some SQL to update from there to the main table.

SQLBulkCopy inserts a new row with NULL values for all columns

寵の児 提交于 2019-11-28 10:44:45
问题 I have this code which works fine and loads the excel data into an SQL table. The only problem is that it also inserts a new row with NULL values for all columns. using (OleDbConnection excel_con = new OleDbConnection(conString)) { excel_con.Open(); string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString(); DataTable dtExcelData = new DataTable(); using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + Path.GetFileName

Possible to get PrimaryKey IDs back after a SQL BulkCopy?

别说谁变了你拦得住时间么 提交于 2019-11-28 08:18:40
I am using C# and using SqlBulkCopy. I have a problem though. I need to do a mass insert into one table then another mass insert into another table. These 2 have a PK/FK relationship. Table A Field1 -PK auto incrementing (easy to do SqlBulkCopy as straight forward) Table B Field1 -PK/FK - This field makes the relationship and is also the PK of this table. It is not auto incrementing and needs to have the same id as to the row in Table A. So these tables have a one to one relationship but I am unsure how to get back all those PK Id that the mass insert made since I need them for Table B. Edit

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

拥有回忆 提交于 2019-11-28 05:27:46
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.KeepIdentity)) { bulkCopy.BatchSize = CustomerList.Count; bulkCopy.DestinationTableName = "dbo.tCustomers"; bulkCopy.ColumnMappings.Clear(); bulkCopy.ColumnMappings

SqlBulkCopy into table that Default column values fails when source DataTable row has DBNull.Value

独自空忆成欢 提交于 2019-11-28 00:55:00
问题 Update: Here is my solution I have a table defined as: CREATE TABLE [dbo].[csvrf_References] ( [Ident] [int] IDENTITY(1,1) NOT NULL, [ReferenceID] [uniqueidentifier] NOT NULL DEFAULT (newsequentialid()), [Type] [nvarchar](255) NOT NULL, [Location] [nvarchar](1000) NULL, [Description] [nvarchar](2000) NULL, [CreatedOn] [datetime] NOT NULL DEFAULT (getdate()), [LastUpdatedOn] [datetime] NOT NULL DEFAULT (getdate()), [LastUpdatedUser] [nvarchar](100) NOT NULL DEFAULT (suser_sname()), CONSTRAINT

Sql Bulk Copy/Insert in C#

早过忘川 提交于 2019-11-27 22:13:20
I am new to JSON and SQLBulkCopy. I have a JSON formatted POST data that I want to Bulk Copy/Insert in Microsoft SQL using C#. JSON Format: { "URLs": [{ "url_name": "Google", "url_address": "http://www.google.com/" }, { "url_name": "Yahoo", "url_address": "http://www.yahoo.com/" }, { "url_name": "FB", "url_address": "http://www.fb.com/" }, { "url_name": "MegaSearches", "url_address": "http://www.megasearches.com/" }] } Classes: public class UrlData { public List<Url> URLs {get;set;} } public class Url { public string url_address {get;set;} public string url_name {get;set;} } How can I do that