Re: Fastest db methods?
From: Pablo Castro [MS] (pablocas_at_online.microsoft.com)
Date: 04/26/04
- Next message: Tony: "testing for "" blank nulls"
- Previous message: Angel Saenz-Badillos[MS]: "Re: Unofficial SxS poll"
- In reply to: B0nj: "Fastest db methods?"
- Next in thread: Bonj: "Re: Fastest db methods?"
- Reply: Bonj: "Re: Fastest db methods?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 26 Apr 2004 12:52:54 -0700
Please see comments inline. Note that these answers are strictly about raw
performance. There might be other factors that may cause negative
side-effects, such as scalability issues (for example, a SqlDataReader is
usually very fast, but if you keep it open for a long time it can hurt
scalability of an application that has multiple concurrent clients).
-- Pablo Castro Program Manager - ADO.NET Team Microsoft Corp. This posting is provided "AS IS" with no warranties, and confers no rights. "B0nj" <anonymous@discussions.microsoft.com> wrote in message news:4867C257-DE3F-40B1-A66C-981CAC0729F0@microsoft.com... > Could someone tell me which is faster, or no difference, between: > > Which is the fastest out of the following two methods??? > Reading a recordset using SqlDataAdapter.Fill(a_dataset) / reading a recordset using SqlDataReader ?? SqlDataAdapter.Fill() uses a SqlDataReader under the covers, so adapter.fill is "reader time + adapter work time". So SqlDataReader is faster, as long as you consume it right away. > > Which is the fastest out of the following two methods??? > Reading a recordset using SqlDataAdapter.Fill(a_dataset) / reading a recordset using SqlDataReader *after* doing an ExecuteNonQuery on the same command (after changing an in parameter's value to enable the SQL to be optimized) in to glean output parameters (which need to be used during the reading of the records) If what you need is some information up-front, you can pack that information as a single-row result-set and send it to the client and the first result from your stored-proc, and then send the actual resultset. For example (call it "pseudo-TSQL" :): declare @a int declare @b int set @a = get_value_for_a set @b = get_value_for_b -- send a couple of scalar values first as a single-row resultset select @a, @b -- now send the real resultset(s) select c1, c2, c3, ... FROM mytable .... In the client you now need only 1 call to ExecuteReader. The first result will be the single-row scalars table, and the second (after calling NextResult on the reader) will be your real resultset. Note that a resultset is more expensive than output parameters, but if you save a round-trip by using it then it's a good deal. > > Which of the following three is faster, or none at all??? > Accessing fields using dr.GetInt32(0) / dr["fieldname"] / or dr[0] ?? GetInt32(0)
- Next message: Tony: "testing for "" blank nulls"
- Previous message: Angel Saenz-Badillos[MS]: "Re: Unofficial SxS poll"
- In reply to: B0nj: "Fastest db methods?"
- Next in thread: Bonj: "Re: Fastest db methods?"
- Reply: Bonj: "Re: Fastest db methods?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|