SQLBULKCOPY class - number of records copied
-
Hi, In one of the tasks, we are using sqlbulkcopy class of .net with three parameters - source db info, destination db info, query to be used to transfer data. We are trying to see if we can get a count of the number of rows that are actually transmitted by the above command. Is there any way to do that? sqlbulkcopy class does not seem to have any attribute that would give this information. Is there any direct or indirect way? Thanks in advance sb
-
Hi, In one of the tasks, we are using sqlbulkcopy class of .net with three parameters - source db info, destination db info, query to be used to transfer data. We are trying to see if we can get a count of the number of rows that are actually transmitted by the above command. Is there any way to do that? sqlbulkcopy class does not seem to have any attribute that would give this information. Is there any direct or indirect way? Thanks in advance sb
Looking at the MSDN docs there's no nice way of doing this. Their examples all suggest doing a "pre-work" row count, then doing the BulkCopy, then doing a "post-work" row count (which will obviously give you the final count). http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx[^] There is an event fired
SqlRowsCopied
but it looks like it only fires after a fixed number of rows have been copied (so if you set theNotifyAfter
property to 50 and copy 99 rows you'll only get notified once), although it might fire when it completes as well (I'll leave that for you to check). http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.sqlrowscopied.aspx[^] HTH