The fastest Normal ADO.NET or Microsoft Best Practise EnterpriseLibrary
-
So I got 2 classes one I wrote to interrogate databases using normal ADO: Mine:
SqlConnection myConnection = new SqlConnection(m_sConnectionString); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout myConnection.Open(); SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection); return result;
Microsoft WaySqlDatabase dbSvc = new SqlDatabase(m_sConnectionString); DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery); return ((SqlDataReader)dbSvc.ExecuteReader(dbCommand));
What's faster? My way:SqlConnection myConnection = new SqlConnection(m_sConnectionString); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout // Use a DataTable – required for default paging SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand); DataTable myTable = new DataTable(); myAdapter.Fill(myTable); myConnection.Close(); myConnection.Dispose(); myConnection = null; return (myTable);
Microsoft Way:SqlDatabase dbSvc = new SqlDatabase(m_sConnectionString); DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery); DataTable dtData = null; DataSet dsData = dbSvc.ExecuteDataSet(dbCommand); dtData = dsData.Tables[0]; return (dtData);
Comments? Ideas? Al My eMail control My Blog -
So I got 2 classes one I wrote to interrogate databases using normal ADO: Mine:
SqlConnection myConnection = new SqlConnection(m_sConnectionString); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout myConnection.Open(); SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection); return result;
Microsoft WaySqlDatabase dbSvc = new SqlDatabase(m_sConnectionString); DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery); return ((SqlDataReader)dbSvc.ExecuteReader(dbCommand));
What's faster? My way:SqlConnection myConnection = new SqlConnection(m_sConnectionString); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout // Use a DataTable – required for default paging SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand); DataTable myTable = new DataTable(); myAdapter.Fill(myTable); myConnection.Close(); myConnection.Dispose(); myConnection = null; return (myTable);
Microsoft Way:SqlDatabase dbSvc = new SqlDatabase(m_sConnectionString); DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery); DataTable dtData = null; DataSet dsData = dbSvc.ExecuteDataSet(dbCommand); dtData = dsData.Tables[0]; return (dtData);
Comments? Ideas? Al My eMail control My BlogWell, I run the test using an abstract class, and after a while I cannot tell you if mine or MS is slower. I may back to the drawing board to build a new one to use. This are my results: http://alpascual.com/blog/al/archive/2006/05/12/176.aspx[^] Cheers Al My eMail control My Blog
-
Well, I run the test using an abstract class, and after a while I cannot tell you if mine or MS is slower. I may back to the drawing board to build a new one to use. This are my results: http://alpascual.com/blog/al/archive/2006/05/12/176.aspx[^] Cheers Al My eMail control My Blog
When doing performance tests it is often very difficult to see small difierences on a single operation. I usually try several hundred iterations (accumulating the timing results with each iteration using a high precision timer class that calls QueryPerformanceCounter) and look at the average performance. This smoothes out minor jitter caused by the OS doing stuff, and usually gives a better measure, especially when the individual operation times are small. We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest. Patricia Aburdene