c# SqlBulkCopy - hot to get the raw sql query

c# sqlbulkcopy sql-server

Question

I am using the c# and SqlBulkCopy to insert some records at once to my db. the records list is small up to a 100-200 records.

here is my code:

 using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString))
            {
                bulkCopy.DestinationTableName = destinationTableName;

                bulkCopy.WriteToServer(reader);
            }

I have a time out exception from time to time and I would like to get the raw sql query in order to investigate some more. can anybody tell me how do I pull that out of the SqlBulkCopy object?

Popular Answer

Try setting BulkCopyTimeout property. I think by default your connection timeout is used.

I don't think you can get the SQL out of BulkCopy as I don't it's doing regular INSERTs. You could try to run SQL Profiler.

If you want to generate INSERT statements for inserting existing data (so you can run it on a different database) you could use SQL Data Compare from Red Gate. I think they have a free version available.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why