Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# SqlBulkCopy - hot to get the raw sql query

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?

like image 593
Gidi Avatar asked Oct 16 '25 18:10

Gidi


1 Answers

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.

like image 183
Jakub Konecki Avatar answered Oct 18 '25 09:10

Jakub Konecki