Interesting... see inlin
----- Cowboy (Gregory A. Beamer) wrote: ----
B0nj said:
Could someone tell me which is faster, or no difference, between
Reading a recordset using SqlDataAdapter.Fill(a_dataset) / reading
recordset using SqlDataReader ?
I have an ex-coworker who was a performance freak. All he was worried abou
was performance. His apps were difficult, overall, to maintain, as companie
normally hire advanced devs for initial development and junior devs fo
maintenance. I am not faulting his push for pure performance, if the app
needed it, but most apps are well below the performance bar, even usin
DataSets. I do not see making the code more complex for a few millisecond
of CPU time, unless the extra perf is needed. As such, "which is faster" i
a horrible question in most instances
I agree
I got to be a bit of a 'code speed nutter' a bit ago too. However I realised what road I was going dow
and realised it was one with too much effort for too little gain, so I made a conscious effor
to always spend a bit of time thinking about how to strike the balance between maintainabilit
and performance, (and other things like development time and genericity). IOW, I make sur
it is at least a certain percentage as fast as it could physically possibly be, and then from ther
make it nice, clean, maintainable code
However, .NET is quite new to me and I always like to at least know which are the faster methods
and what each one is doing under the hood, as in some scenarios it seems there are multipl
ways of achieving the same end
Off my soapbox
Which is faster? SqlDataReader
Why? Behind the scenes, the DA uses a DataReader to fill the table, so yo
are employing more software with the DataAdapter > DataSet (DataTabl
actually) method
This is what I thought. Thanks for confirming it
DataReaders are great for displaying data. Realize, however, that Whidbe
throws a monkey wrench into the mix, as the default data model requires fa
less code and relies heavily on DataSets. Your code will still wor
(DataReader or DataSet), but you will move farther away from a system wher
junior devs who learn Whidbey .NET can keep up with your code
Sod Whidbey - we've no reason to buy Whidbey. We'd still be with VB6 and Interde
if we'd have had licenses for them. But one day, the management found we didn't hav
a license for my copy of VB6, so decided to buy me a nice shiny new .NET 2k3 EA
the license for which the management believe to be valid for VB6..
whether it is or not I don't know, but I'll go along with it! I haven't used VB6 for ages now
Now we've got the license, we'll always have it - it doesn't expire. So however old technolog
it gets - it may not have 2005, -07, -10 etc. technology but at least we'll be able to use it t
build intranet applications. The concept of the thin-client app and the web browser isn'
going away from offices for a LONG time - certainly from ours if there's no reason for it to
There are a main IT department with apparently about 80 developers, not to boast bu
they can't prove themselves like we can due to the need to constantly have scoping meeting
and draw up formal specifications. Hence, our dept are seen to be much better, even thoug
there are probably a few guys down there who are pretty hot at C++ - they build 'wide scale
apps for the field, probably in VC6 or VB6. Thus, we are the first to get .NET because we are thought t
be the best - no one else in the company has got .NET but us.
DataReaders are great if you are not using the extra FUD with th
FUD
For a bit of perf, you ca
strongly type your datasets
That sounds a bit crap to me. It's that old concept that harks back to old days
of having a class for every single recordset the application needs to use. Well I'm sorr
but I haven't got anything like enough time to create a class for each recordset!
If you truly are running up against the bar
Nah. I'm not. It's currently running on the web server of my PC (don't laugh - it's
fine for development and 'showing the bosses my work' purposes), and when (and
probably only when) management are happy with what can be done software wise, they'll
shell out for some new hardware to host it on. I've told them we're having SQL server and IIS
on the same machine, which I'm sure will be fine to start with as there are other SQL boxes to
do the pre-aggregation.
the boss cannot shell out for a bigger box,
They can, and will.
I'm in the lucky position of developing a system that's mainly going to be
used by directors - this has two benefits (for me): (1) there aren't as many of them, so there's not going
to be like 10,000 people hitting my site as soon as it's launched, and (2) they're in a position such
that if they like it, they'll pump money our way.
I do not understand running the command twice (once cmd.ExecuteNonQuery and
one cmd.ExecuteReader). Can you explain a real world reason for this?
See reply to somebody else. Basically I would have only used this if the answer had been
"a DataSet is horribly slow, and will take many times longer than a datareader whatever the number
of records." But it wasn't, as I expected - but I'm still finding my footing with .NET still, and I want to
be sure I'm doing the right thing.
Overall, I chain output using stored procedures into a DataSet, so I can run
any number of commands in sequence, including the equivalent of
ExecuteNonQuery followed by ExecuteReader.
So if I have a stored procedure that returns multiple recordsets, I would use a dataset - as it can
have multiple tables. That makes sense... got any example code so I can see how it works?
GetInt32(0)
Why? You are optimizing the data pull by telling the compiler what is
happening. With the other two, you really need to cast out the int to be
safe.
Here is another question. Which is easier to maintain?
dr["fieldname"]
why? Easy. Even if I change the command order, I can still pull the correct
field.
True, true. Like I say, I try to strike a balance...
For the most part, I err on the side of maintainability, as I never know who
will inherit my code.
For me, 'maintainable' code is code that follows the notion that management see
that I'm capable of maintaining it myself, and more
importantly I can maintain it within a short timeframe,
therefore it's maintainable. I couldn't give a toss about the plight of developers
following in my footsteps, I'm afraid. At work, I only care about two things:
how well our department's systems are working - thus how much efficiency our
department adds to the company and how much brownie points our department gets,
and how well I personally am seen to be, and my own financial gains.
There's no point adding your own morals to your job. It sounds selfish, but you might aswell
follow what's best for yourself only - as whatever the right thing to do is, will dictate that.
If the company recognises that it's in the company's best interest for senior developers to give more
training to junior developers, then they'll either say "train them, or else you'll be out on your ear", or
"train them, and you'll get a bonus". Either way, it's in the senior developer's best interest to then give
training to the junior developers. But not otherwise! Companies have to be run from a central standpoint,
and can't be influenced by people who think they know better than the layman. A corporation has to be
one unit - acting as one controlled, single entity. So you might as well just be like an ant - selfish, but
serving the maximum efficiency to the greater good.
Not criticising you in any way or saying you're any of those things, but it just reminded me recently of a
post from a guy whose users were looking up VBA password crackers on the internet, and he was spitting
feathers because they'd cracked his access database and weren't using his specially designed interface.
AARRRRGGGHHHHH!!!!!! People like that really irritate me. (The access developer that is, not his users!)
Entry level .NET dev $40k <that's me! but I'm only young yet.
Mid level .NET dev $65k
Senior level .NET dev $85k
If I make an extremely maintainable solution, an entry level dev should be
able to maintain most of the code. This saves the company between $25k -
$45k per year for maintenance.
Good for you! I'm not that interested in company profits myself - I leave that to the
accountants!