Click here to Skip to main content
12,696,632 members (31,671 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# SQL-Server ADO.NET
I am new to Database interection with C#, I am trying to writing 10000 records in database in a loop with the help of SqlCommand and SqlConnection objects with the help of SqlTransaction and committing after 5000. It is taking 10 seconds to processed.

SqlConnection myConnection = new SqlConnection("..Connection String..");
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "exec StoredProcedureInsertOneRowInTable Param1, Param2........";
myCommand.Connection = myConnection;
SqlTransaction myTrans = myConnection.Begintransaction();

for(int i=0;i<10000;i++)
  myTrans = myConnection.BeginTransaction();
  mycommand.Transaction = myTrans;

Above code is giving me only 1000 rows write/sec in database.

But when i tried to implement same logic in T-SQL and execute it on Database with SqlManagement Studio the it gave me 10000 write/sec.
When I compare the behaviour of above two approch then it showes me that while executing with ADO.Net there is large number of Logical reads.

my questions are:
1. Why there is logical reads in ADO.Net execution?
2. Is tansaction ahve some hand shaking?
3. Why they are not available in case of management studio?
4. If I want very fast insert transactions on DB then what will be the approach?
Posted 27-Jan-11 3:18am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's always going to be the case that making a ton of SQL calls is slower than making one. That's why you should never do what you're doing. Instead, I'd put the data I was pushing in to an XML document and use OpenXML to pass it to SQL Server.
vikram_eck 28-Jan-11 1:10am
I understand that the approach I am using is incorrect but it is my requirement as I have to store real time transactions, real time in to Database as other applications may willing to use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 27 Jan 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100