SQLBulkCopy 与 Transaction 结合使用,并在每次复制批次时触发一个事件
我目前正在通过 SQLBulkCopy 和 Transactions 将数据上传到 MS SQL 服务器。我希望能够在每批上传后引发一个事件(我已经尝试过 SQLRowsCopied 事件,但它不起作用,请参阅下面的引用)
MSDN 引用:
在执行大容量复制操作期间,连接中不支持任何操作(例如事务活动),建议您不要使用在 SqlRowsCopied 事件期间使用的相同连接。但是,您可以打开不同的连接。
所以我基本上不能拥有我的蛋糕吃掉它:(有谁知道这个问题的解决方案,因为我想在每批上传后触发一个事件。
感谢您的帮助。
Im currently uploading data to MS SQL server via SQLBulkCopy and Transactions. I would like to be able to raise an event after each batch has been uploaded (I have already tried SQLRowsCopied event and it doesnt work, see quote below)
MSDN quote:
No action, such as transaction activity, is supported in the connection during the execution of the bulk copy operation, and it is recommended that you not use the same connection used during the SqlRowsCopied event. However, you can open a different connection.
So i basically cant have my cake and eat it :( Does anyone know a solution around this as i would like to fire an event after each batch has been uploaded.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终决定使用内部交易。 ATM 似乎工作正常,如果遇到错误,当前批次将回滚。关于本上面的评论,我尝试了这一点,但这是不可能的,它不像循环遍历一段可以引发事件的代码。最后我使用了notifyafter属性,它在复制x行后引发一个事件,以引发我的事件。可能不是最好的方法,但我想不出更好的方法。希望有人觉得这很有用。
I have finally decided to use an internal transaction. ATM it seems to be working fine if an error is encountered the current batch is rolled back. Regarding Ben's comment above, i tried this but its not possible, its not as though it loops through a section of code where you could raise an event. In the end i used the notifyafter property, which raises an event after x rows have been copied, to raise my event. Probably not the best way of doing it but i couldnt figure out a better way. Hope someone finds this useful.