SqlBulkCopy.WriteToServer() keep getting “connection is closed”

前端 未结 3 1528
野性不改
野性不改 2021-01-22 07:44

This makes no sense to me but maybe someone with keener eyes can spot the problem.

I have a Windows service that uses FileSystemWatcher. It processes some files and upl

3条回答
  •  Happy的楠姐
    2021-01-22 08:12

    Looks like an issue with it being Async.

    Please let me know if I wrong, but what I noticed is you have your SqlBulkCopy and ObjectReader in a using statement which is great, however, you are doing all the processing asynchronously. Once, you call it and it starts doing work, your using statements are disposing of your objects which will also kill your connection.

    The odd thing is that it sounds like it works sometimes, but perhaps it just becomes a race condition at that point.

提交回复
热议问题