Last post Feb 01, 2016 09:26 AM by Weibo Zhang
Jan 29, 2016 02:58 PM|Nirav Mungara|LINK
How could we found BULK INSERT completion percentage in SQL server using C#?
I have tried with the following query:
SELECT d.name databasename,
estimated_finish_time = DATEADD(MILLISECOND,estimated_completion_time, CURRENT_TIMESTAMP) FROM sys.dm_exec_requests r INNER JOIN sys.databases d ON r.database_id = d.database_id WHERE r.command like '%BULK INSERT%'
But I am unable to get the result as per the requirement.
Feb 01, 2016 09:26 AM|Weibo Zhang|LINK
Hi Nirav Mungara,
According to the following link that’s about the “sys.dm_exec_requests” you could first check whether there is the command value is “BULK INSERT”. For this testing, you could running a Bulk insert query and then query
select distinct command from sys.dm_exec_requests to check.
If there’s no the related values, you could first refer to the following code to get the Bulk Insert informations and then get the “Session_Id”, then you could pass this “Session_Id” to “sys.dm_exec_requests” get the expected result.
As a workaround, you could just running “select count(*) from [TableName]” to get current rows count. But, maybe in this method, the result would be in a slight delay.
Besides, you could have a look at the SqlBulkCopy.SqlRowsCopied Event, in C# code, you could use this event to get what you want.