3

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gidi
  • 181
  • 1
  • 10

1 Answers1

3

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.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • would be interesting to see if you do actually get anything from SQL profiler. The doc's don't really say what it does under the hood. – Liam Oct 22 '13 at 10:27
  • [this](http://stackoverflow.com/a/12189324/542251) seems to *imply* that you won't get anything in profiler, hardly definitive though. – Liam Oct 22 '13 at 10:29
  • 1
    this is what I saw in sql proiler: insert bulk destinationTableName ([colAName] BigInt, [colBName] NVarChar(250) COLLATE SQL_Latin1_General_CP1_CI_AS) – Gidi Oct 22 '13 at 11:09
  • @Gidi - Yes, that's what you will get in Profiler. – Jakub Konecki Oct 22 '13 at 11:57