sqlbulkcopy

How to add 'Real' type to a DataTable?

ⅰ亾dé卋堺 提交于 2020-06-01 07:36:07
问题 I am bulkcopying records from a csv file to a sql table. The sql table has columns that are varchar, and columns that are real datatype (based on the csv attributes we are given) Lets suppose that the first 7 columns are the Foreign Keys of varchar(100), and the rest of the 80+ columns are Real datatype. During the bulk copy, I used Out-DataTable function because apparently thats the most efficient way to bulk copy (especially with our files containing 1000's of records). However, I am

Bulk upload strategy for SQL server

人走茶凉 提交于 2020-01-30 11:35:14
问题 I am uploading data from CSV to SQL table using the following function. Is there a better way to do it? I am concerned about , right now, connection hold for long time. Hence need to be reduced. public bool SaveProxyBulkUploadData(List<AddServerPError> saveBulkUploadData) { try { foreach (AddServerPError addServetData in saveBulkUploadData) { DbCommand dbCmd = CitiScriptExecutionDB.GetStoredProcCommand("USP_HS_InsertProxyBulkUploadData"); CitiScriptExecutionDB.AddInParameter(dbCmd, "@groupid"

Looping in Trigger?

拥有回忆 提交于 2020-01-25 23:46:00
问题 I got this following scenario, There are four tables COUNTRY, STATE, CITY, STREET And I have the excel file with the records of the above..possibly 2000 rows as of now. I used SqlBulkCopy to import the data to a temp table, lets name the table IMPORT. And i wrote one trigger for insert on the IMPORT table which gets the inserted record and splits country, state, city, street then inserts them to the respective table. In this trigger i got to do some conditional check,like, if COUNTRY name is

Looping in Trigger?

情到浓时终转凉″ 提交于 2020-01-25 23:45:03
问题 I got this following scenario, There are four tables COUNTRY, STATE, CITY, STREET And I have the excel file with the records of the above..possibly 2000 rows as of now. I used SqlBulkCopy to import the data to a temp table, lets name the table IMPORT. And i wrote one trigger for insert on the IMPORT table which gets the inserted record and splits country, state, city, street then inserts them to the respective table. In this trigger i got to do some conditional check,like, if COUNTRY name is

How do I bulk insert two datatables that have an Identity relationship

时光总嘲笑我的痴心妄想 提交于 2020-01-25 02:10:27
问题 I'm using SQLBulkCopy, in pseudocode I do this: make new Employee datatable make new EmployeeAddress datatable populate employee table but don't specificy employeeId as it's identity populate EmployeeAddress datatable, but it contains an employeeId field write both datatables to the database by doing this twice and changing the table name: . using (var bulk = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity & SqlBulkCopyOptions.KeepNulls)) { bulk.BatchSize = 25; bulk

How do I bulk insert two datatables that have an Identity relationship

狂风中的少年 提交于 2020-01-25 02:10:06
问题 I'm using SQLBulkCopy, in pseudocode I do this: make new Employee datatable make new EmployeeAddress datatable populate employee table but don't specificy employeeId as it's identity populate EmployeeAddress datatable, but it contains an employeeId field write both datatables to the database by doing this twice and changing the table name: . using (var bulk = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity & SqlBulkCopyOptions.KeepNulls)) { bulk.BatchSize = 25; bulk

SQL Server: Bulk Insert into table with computed column

萝らか妹 提交于 2020-01-24 22:23:29
问题 I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp. My bcp command: bcp Test.dbo.myFirstImport IN D:\myFirstImport.txt -f D:\myFirstImport.xml –T My table: CREATE TABLE [dbo].[MyFirstImport]( [PersonID] [smallint] NULL, [FirstName] [varchar](25) NULL, [LastName] [varchar](30) NULL, [BirthDate] [date] NOT NULL, [YearMonthCom] AS (datepart(year,[BirthDate])*(100)+datepart(month,[BirthDate])) PERSISTED ) ON [PRIMARY] My Data (tab separated): 1

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

末鹿安然 提交于 2020-01-23 13:29:07
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

大兔子大兔子 提交于 2020-01-23 13:28:09
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

Inserting GUIDs with SqlBulkCopy

给你一囗甜甜゛ 提交于 2020-01-23 05:28:04
问题 I'm trying to do a bulk insert with the SqlBulkCopy class from flatfiles created by the SQL Server Management Import Export Wizard. The files are comma separated. One row in the file can look like this: {DCAD82A9-32EC-4351-BEDC-2F8291B40AB3},,{ca91e768-072d-4e30-aaf1-bfe32c24008f},900001:1792756,900001:1792757,basladdning,2011-04-29 02:54:15.380000000,basladdning,2011-04-29 02:54:15.380000000,{20A3C50E-8029-41DE-86F1-DDCDB9A78BA5} The error I get is: System.InvalidOperationException was