sqlbulkcopy

How does SqlBulkCopy circumnavigate foreign key constraints?

本小妞迷上赌 提交于 2020-01-10 11:49:05
问题 I used SqlBulkCopy to insert a collection of rows into a table. I forgot to set an integer value on the rows. The missing column is used to reference another table and this is enforced with a foreign key constraint. For every row inserted, the final integer value was zero and zero didn't identify a row in the related table. When I modified the value to a valid value and then tried to switch it back to zero it wouldn't accept it. So my question is how does SqlBulkCopy manage to leave the

Ordering in SQL Server

此生再无相见时 提交于 2020-01-05 04:33:06
问题 I have a situation where I am importing many rows of data from text files. The import process occurs using SqlBulkCopy and initially loads into a staging table. I perform some validation on this data and would like to be able to report back to the user which line of the file is in error if validation fails. I was hoping to simply use ROW_NUMBER() along with the default ordering of the SELECT on my staging table, but there are some questions on SO that have suggested I won't be able to do this

How to keep row order with SqlBulkCopy?

 ̄綄美尐妖づ 提交于 2020-01-02 08:25:34
问题 I'm exporting data programatically from Excel to SQL Server 2005 using SqlBulkCopy. It works great, the only problem I have is that it doesn't preserve the row sequence i have in Excel file. I don't have a column to order by, I just want the records to be inserted in the same order they appear in the Excel Spreadsheet. I can't modify the Excel file, and have to work with what I've got. Sorting by any of the existing columns will break the sequence. Please help. P.S. Ended up inserting ID

SqlBulkCopy insert order

徘徊边缘 提交于 2020-01-02 07:04:51
问题 To copy data from one database to another in different server with same schema, I am planning to use SqlBulkCopy class from C sharp library. Whether SqlBulkCopy will maintain the same order as it is in the datatable while inserting the records ? Example: id is the identity column. Server1, db1 TableA id name 1 name10 2 name20 3 name30 4 name40 Server2, db1 TableA id name 1 name1 2 name2 3 name3 4 name4 .......... .......... 5000 name22 5001 name33 Step1: var dt = select * from server1.dbo

SqlBulkCopy insert order

旧城冷巷雨未停 提交于 2020-01-02 07:04:22
问题 To copy data from one database to another in different server with same schema, I am planning to use SqlBulkCopy class from C sharp library. Whether SqlBulkCopy will maintain the same order as it is in the datatable while inserting the records ? Example: id is the identity column. Server1, db1 TableA id name 1 name10 2 name20 3 name30 4 name40 Server2, db1 TableA id name 1 name1 2 name2 3 name3 4 name4 .......... .......... 5000 name22 5001 name33 Step1: var dt = select * from server1.dbo

Excel File upload in asp.net using SqlBulkCopy

送分小仙女□ 提交于 2020-01-01 18:33:03
问题 I am uploading excel file in asp.net c# using following code.It is working fine but problem is that in excel file some column values are always numeric and if some of those numeric values are in text format then it is uploading null value. This is my code - any suggestion please. if (!Convert.IsDBNull(FileUpload.PostedFile) & FileUpload.PostedFile.ContentLength > 0) { //FIRST, SAVE THE SELECTED FILE IN THE ROOT DIRECTORY. FileUpload.SaveAs(Server.MapPath(".") + "\\" + FileUpload.FileName); //

php postgresql pdo copy from stdin

不想你离开。 提交于 2020-01-01 05:23:07
问题 COPY table_name ( field1, field2, field3) FROM STDIN CSV; 1,2,"q w" 3,4,"a s" 5,6,d \. How to execute this query by PDO ? Update: Problem is PDO driver executes this query as statement. For example, if you paste it into pgAdmin, it throws an error. I need execute it in psql : C:\Users\User>psql -e -h localhost -U postgres db_name psql (9.1.2) db_name=# COPY table_name ( field1, field2, field3) FROM STDIN CSV; COPY table_name ( field1, field2, field3) FROM STDIN CSV; Enter data to be copied

sqlbulkcopy from Excel via ACE.OLEDB truncates text to 255 chars

天大地大妈咪最大 提交于 2019-12-31 04:33:08
问题 Pretty straight-forward import using SqlBulkCopy: string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\""; using (OleDbConnection excelConnection = new OleDbConnection(excelConnectionString)) { excelConnection.Open(); OleDbCommand cmd = new OleDbCommand("Select " + fileID.ToString() + " as [FileID], * from [Sheet1$] where [Text] IS NOT NULL", excelConnection); OleDbDataReader dReader = cmd

Rollback for bulk copy

时光毁灭记忆、已成空白 提交于 2019-12-30 08:16:29
问题 I have an application that make a copy from my database by bulk copy class in c#. Can I rollback the bulk copy action in sql server when occur an exception? 回答1: MSDN article: Performing a Bulk Copy Operation in a Transaction or the newer documentation: Transaction and Bulk Copy Operations | Microsoft Docs using (SqlTransaction transaction = destinationConnection.BeginTransaction()) { using (SqlBulkCopy bulkCopy = new SqlBulkCopy( destinationConnection, SqlBulkCopyOptions.KeepIdentity,

Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy?

点点圈 提交于 2019-12-30 00:14:48
问题 Very simple question: is it possible to use System.Transactions.TransactionScope together with SqlBulkCopy ? The documentation Transaction and Bulk Copy Operations doesn't mention anything (at least as of .NET 4.0) and my testing indicates it does not automatically enlist with TransactionScope . 回答1: SqlBulkCopy never enlists into a transaction. SqlCommand also does not do that. Common misconception. The enlistment is performed at the time SqlConnection.Open is called. After that, anything