如何收集大容量复制操作期间发生的错误 [英] How to get collection of errors that occurred during the bulk copy operation

查看:60
本文介绍了如何收集大容量复制操作期间发生的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用SqlBulkCopy程序将CSV文件复制到Sql Server数据库中. 工作正常.但是问题是复制数据时忽略了一些行
由于限制,如果列数据类型不匹配,则提供的数据是错误的,
而且它没有引发异常.

我想要的是,是否有任何类或属性将为我提供BCP期间发生的错误.我必须为SqlServer,Oracle和DB2实现此功能.在DB2中,属性DB2ErrorCollection提供有关
的信息 一样.

-Dattatrya Moin

Hi,

I am using SqlBulkCopy Program for copying CSV files into Sql Server database.
It''s working fine. But the problem it is ignoring some rows while copying data
because of constraints, if column datatype is not matched, data provided is wrong,
And it is not raising an Exception.

What I want is, Is there any class or property which will give me what errors occurred during BCP. I have to implement this functionality for SqlServer, Oracle and DB2. In DB2 the property DB2ErrorCollection is giving the information regarding
same.

- Dattatrya Moin

推荐答案

由于SqlBulkCopy的性质,错误处理的方式不多.

此链接可能有帮助.基本上,它提供了两种可能有帮助的解决方案.

> http://stackoverflow.com/questions/1004525/sqlbulkcopy-error-handling-continue-错误时 [ ^ ]

基本上,我将如何操作是首先插入到临时表中.然后,使用单独的功能/sp,您可以通过更多控制和错误处理将数据移至活动表,甚至过滤掉不满足验证要求和约束的行.
Due to the nature of SqlBulkCopy there is not much in the way of error handling.

This link maybe of help. Basically it gives two possible solutions that could help.

http://stackoverflow.com/questions/1004525/sqlbulkcopy-error-handling-continue-on-error[^]

Basically how I would do it is by inserting into a temp table first. Then using separate function / sp you could then move the data across to the live table with more control and error handling or even filter out rows that do not meet the validation requirements and constraints.


这篇关于如何收集大容量复制操作期间发生的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆