SqlCommand slow on INSERT




I have a c# program that loops through a table on a DB2 database.

On each iteration it assigns data to values in the SqlParameter collection. The command text is an INSERT statement to a Sql Server database, run with an .ExecuteQuery I enclosed the loop in a SqlTransaction and commit it at the end.

I timed the program and it inserts about 70 records a second...which I think is sort of slow...so I set up some Debug.WriteLines to show where the time was being spent.

The DataReader loop to the DB2 table is instantaneous. Almost 0s spent getting each record. Same with assigning values.

The slow step is the actual execution of the SqlCommand. However, I also ran a SQL Trace and monitored the execution of the statement on the server. It took 0s to execute. The SqlCommand itself is adding an extra 0.01s to 0.03s which can add up over the course of hundreds of thousands of records.

So the only overhead is running .ExecuteQuery on the SqlCommand object(!) Is there anyway to reduce or minimize this overhead, or a setting that can affect performance.

I mean if my external source and target are running at 0s - my code shouldn't be adding overhead to run a command!
.