Visual Studio 2005 Debugging Tip

Have you ever been debugging an ASP.NET 2.0 application and you see "First Chance Exception XXX" in the Output Window while you are putting the app through its paces in Debug mode, but the IDE never breaks on any of them?

And you are saying to yourself, How can I debug this thing if all I see is cryptic messages in the Output Window but no source code, line numbers or anything else?

What you want to do is tell the Debugger to Break on all Managed Code Exceptions. Here's how:

1) In the IDE, up top, hit "Debug" and Choose "Exceptions". You will see a dialog with a Treeview (collapsed) the second node of which reads "Common Language Runtime Exceptions". At the right will be a checkbox. Check this checkbox. (If you want, you can expand the treenode and pick and choose which kinds of exceptions you want the debugger to break on when thrown). You need to check this (these) because the default behavior is "continue".

In fact, you can even add custom exceptions that aren't in the list, that you want the debugger to break on. CTRL-ALT-E brings this dialog up.

Exceptions Dialog- Click to Enlarge

2)Now when you get an exception, everything will come to a screeching halt and you'll break into the debugger. Ain't technology grand?


Few Things to Think About on your way to the Polls

Republicans have some pretty good reasons to show up at their polling places on Election Day. You may not share my views, but I hope you'll take the time to vote, too:

More than 6.6 million new jobs have been created since August 2003, and that's after we inherited a nasty downturn and stock market bubble from the Clinton Administration. Our 4.1% annual growth rate is superior to most other major industrialized nations. The Dow has set record highs multiple times in the past several weeks. Productivity is up, the deficit is down. Real after-tax income has grown by 15 percent since 2001. Inflation has remained low. The tax cuts proposed by President Bush and passed by a Republican Congress are working! And, by the way, all this Liberal BS about "record deficits" is exactly that - BS! The deficit as a percentage of current GDP is right in the historical ballpark, my friend.

Democrats will attempt to mislead you with a lot more of their narrow "statistics", often lacking context, that try to say the Bush Administration hasn't created jobs. Take a look at the stock market again. The Democrats don't have a plan; at least I can't remember seeing one. Their platform is the "BBFCPL" platform: Bash Bush First, Come up with a Plan Later. I'll gladly vote for a Democrat with a plan. Give me Joe Lieberman, I'll vote for him without hesitation. He has a plan! My Chief Statistician, Marge Innovera, says to deal with facts, figures and arithmetic, not emotions. She also says there are both smart Democrats and Republicans.

Although Democrats and liberals mourn The Patriot Act as a gross infringement upon civil liberties, the much-discussed abuses haven't materialized. The law has permitted the CIA and FBI to cooperate and share information about terrorist threats -- at least so long as The New York Times isn't publishing the details of our efforts on the front page or CNN is airing terrorist films showing US service people being sniped at. The British just foiled a major terrorist plot because their anti-terrorist laws have teeth. You know what I think about Civil Liberties? They don't mean a shit if you just got your ass blown off by a bomb!

Republicans in Congress insisted upon and got the first serious immigration restriction in decades. On Oct. 26, the president signed a law that will build a 700-mile fence along our southern border and, what is more important, it does not offer amnesty. There's a lot more to be done, but we've done more in this Administration than any in the last 25 years.

A.Q. Khan's nuclear smuggling network has been dismantled.

John Roberts and Samuel Alito sit on the U.S. Supreme Court.

There hasn't been another terrorist attack on American soil since 9/11.

Libya has surrendered its nuclear program, renounced terrorism, paid compensation, and full diplomatic relations are opening back up.

Many Democrats believe in immediate withdrawal from Iraq. If they succeed in forcing us to leave under these circumstances, the United States will suffer a stinging defeat in the war on terror. The terrorists already believe that they drove the Russians from Afghanistan, and Israel from Lebanon and Gaza. They are convinced they chased us out of Lebanon in 1983 and from Somalia in 1993. According to Osama bin Laden, we are psychologically and spiritually weak. If we leave Iraq now we will totally validate this analysis. We might as well prepare a tape that says "We give up, you win" and drop it off at Al Jazeera! Iraq may not have been the center of the war on terrorism before we went in there. It is now. Geraldo Rivera, who is not exactly a Conservative, got it right when he said "We are gonna be in Iraq like we were in Korea - for the next half century - get over it!". It's a strategic center for us and we need to take pains to do things right, because we will indeed be in Iraq for a very long time.

If Democrats achieve a majority in the House, Barney Frank will chair the Financial Services Committee, Henry Waxman will head the Government Reform Committee, and Alcee Hastings will chair the Intelligence Committee. Good God! Hey, didn't you folks vow to move to Canada if Bush got re-elected? What happened, did Bill O'Reilly sneak into your house at night and steal your car keys?

Democrats believe that the proper response to Kim Jong Il's nuclear tests is "face to face talks." That's what the Clinton administration did for years. Did it work? My seismic sensors say "Unlikely". My general sense about Democratic candidates and politicians right now is that they focus on the negative, rather than proposing real, workable positive solutions for change. It's like a broken MP3. All you hear is "The Bush Adminstration screwed up", "Bush lied", "The Bush Administration is responsible for X, Y and Z", ad nauseum. Hey! What are YOU gonna do that's better? I'm listening, but I don't HEAR ANYTHING. Fact is, you're so consumed by hatred, you can't even THINK!

Iran's leaders have vowed to destroy Israel and the Jews. They think that this is Allah's bidding. Allah (through his prophet, Mohammed) never preached intolerance like this on the scale of Hitler. Allah, at least according to the Koran, never preached intolerance period. The Koran mentions twenty-five prophets by name including Adam, Noah, Abraham, Moses, John the Baptist, Jesus, and Mohammed. These current so-called "Islamic" fanatics do not represent Islam, and they don't know what Allah or Mohammed is. These people are psychotic, and if we don't protect our collective ass, they'll destroy our way of life too. Democrats think we should negotiate with these maniacs. Yikes! I'll be there, pal, at the polling place!

One thing is for sure, no matter what happens in the upcoming elections. If we can't learn to put aside hatred and work together and compromise to solve problems, we're sunk, man.


Web 2.0 Overload Comin' At Ya!

Think about it: There are HUNDREDS of these "Web 2.0" sites that have sprung up in the last year or eighteen months. Most of them are simply re-works of existing concepts: Video sharing, Social Bookmarking, Feed Reading, and so on. They are all competing for the same set of eyeballs, more or less.

Think about the "Web 2.0" sites that you really, really use consistently. I know which ones i use:

Google Reader
Google personalized home page
Flickr (infrequently, though i do have some photos there)
YouTube (I just visit)
Live.com (mostly just visit)

-- That's about it, the "Short list". Sure, i look at the new ones. But almost without exception, I visit once or twice, determine if I am really interested, and you never see me there again.

When I look at this list, there are really only 3 that I ever use consistently:

Digg, mostly for entertainment, because it's populated in the main by 20 and 30 -something Liberal geeks, and I am a bit older and more conservative, so I enjoy smacking them with my non-Liberal "make you think" comments.

Del.icio.us, because it delivers. It delivers bookmarking, tagging, and searching. It's simple, it's fast, and it works. If I've bookmarked something, it's easy to see how many others have done so, and more importantly, it's easy to find similar content based on either a search, or the tags I've assigned. If you look at the bottom of this post, I've got a "Social Link This Page" link that has dozens of these sites on it. The only ones I ever use from the list are Digg and Delicious.

Google Personalized Home Page. Speaks for itself.

What's my point? It's that unless you have a really compelling concept and the abilty to execute it with style, you don't earn my eyeballs. Period!

In fact, right now --- of all the so-called "Web 2.0" offerings in the marketplace, I'd have to say that Google's Personalized Home page is my favorite. Why? Simple- it helps me keep what I need to see and am interested in right in front of my face. It does so easily, I can change it, and it has tabs so I can have plenty of my "Stuff" - whether it's headlines, feeds, Digg, my Gmail inbox, NASA space shot of the day - whatever I want - right on my home page.

And you know what? People's home pages are where their eyeballs are at, pal. If you have a formula that earns you the right to be somebody's home page, you are King Webtard! Anything less, and you are simply swimming with all the other Web 2.0 fish in the pond and chances are slim you'll ever see the eyeballs in any substantial way.

Think about it. Most of this other stuff, no matter how sexy it may seem right now, will be completely gone within one to two years. Del.icio.us will most likely still be here. Google Home page will certainly be. Flickr, YouTube, probably. The others? Heh. Bach's been dead 365 years and he's still popular. Miles Davis's Kind of Blue album came out 45 years ago; it still sells 5000 new copies every week. Web 2.0 sites? -- don't hold your breath.

I leave you with this question to ponder: If all this is Web 2.0, what will Web 3.0 be like, and when will we see it?


Cross-Application Forms Authentication

I've seen some confusion about how and whether you can have a user who has been "Forms-Authenticated" on one application or site be able to go to or be redirected to another application or site (or the "same" application on a web farm, which is essentially the same situation) and not have to re-authenticate.

ASP.NET 2.0 sports a new Forms Auth property, "EnableCrossAppRedirects". This can be set in the Forms Authentication web.config node, e.g.,

enableCrossAppRedirects="true" />

The way this works is that the EnableCrossAppRedirects property is checked within the RedirectFromLoginPage method when the redirect URL does not point to a page in the current application. If EnableCrossAppRedirects is true, then the redirect is performed; if EnableCrossAppRedirects is false, the browser is redirected to the page defined in the DefaultUrl property.

However, this is not sufficient to get you to "First Base". The name, protection, path, validationKey, and decryptionKey attributes must all be identical across all applications. In addition, the encryption and validation keys and the encryption scheme used for cookie data must be exactly the same. If the settings do not match, cookies can't be shared, and cross-app authentication won't work.

Here is an example web.config snippet:

<authentication mode="Forms" >
<!-- The name, protection, and path attributes must match
exactly in each Web.config file. -->
<forms loginUrl="login.aspx"
timeout="30" />

<!-- Validation and decryption keys must exactly match and cannot
be set to "AutoGenerate". The validation algorithm must also
be the same. -->
<machineKey validationKey="C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA1742572A487D940
validation="SHA1" />

I wrote an article about this a long time ago, it' still valid today. There is also a sample page that will generate a machinekey element for you here.


Google Co-op Search and Expression Web (Designer)

Google Co-op search has been worked over very nicely. I am expermenting with one in the footer of these blog entry pages. This particular one does targeted search on .NET-related topics, and searches a long list of blogs, including many from the Microsoft Bloggers OPML, which I have imported. I hope to add more soon.

Here is the homepage of the co-op search.

You can also open these up for collaboration by sending invites to others, and then have a whole group of people that can add target search sites/ blogs to your Search Engine.

This isn't as open as I had hoped, because it appears you have to invite your collaborators first. My theory, instead, is to let anyone add a search target site or blog, and then the admin(s) would either approve or disapprove it. I say this because they've done a very nice job on their custom Google Groups. I started one about open - source software sometime ago (has over 200 members now) and as admin, I can go on and set settings for new users, moderate posts, and even kick somebody off if it becomes obvious that all they joined for was to post job-listing spam. So the Custom Search will need features like this to compete and become a true collaborative environment.

I currently have some 1346 blogs in the search facility (you can add sites in bulk, and it accepts both RSS/ATOM feed urls as well as regular HTML urls to a page or site). You cannot add more than a couple hundred at a time, however, since the JSON dies on the vine with too much baggage. Being able to add straight OPML would be a nice feature.

It's funny that I ran across this today, since I had already started on something similar. Now I'm encouraged to continue working on it. (Mine will be better!)

Expression Web

Working with CSS and positioning is a weak point for a lot of ASP.NET developers, myself included. It's a full-time career to become a professional web designer (and from the looks of many ASP.NET sites, that's a self-fulfilling prophecy) -- codemonkeys simply do not have the time or inclination, except in special cases, to earn those kinds of skills.

CSS support in IE 7.0 has been enhanced quite a bit, with over 200 fixes in the release version of the product. I've always used Dreamweaver to do my positioning and styling, not only because it is good - especially 8.0 which hardly ever crashes - but also because it doesn't mangle server tags from an ASP.NET page. So, I can do my layout and CSS, and then save and reload the page in VisualStudio.NET for server-side coding.

But now there is Expression Web. My first impression? Pretty damn slick. It has CSS features, a "web site" facility that's better than Dreamweaver, and you can actually design and live-preview an ASP.NET page - including Master Pages -- with all the ASP.NET controls right in the Expression designer.

Take a look - it's still Beta, but if they keep working on it like this, its a sure winner.


A Note About C# and Interfaces

Interfaces seems to be one of the biggest conceptual problem areas for beginning developers. Some people just have difficulty understanding what an Interface really is, but more often, developers can understand what it is; it's just that they have difficulty getting a grasp on "what it is for".

Recently on the C# MS Group there was a post that basically revolved around the concept of "why do I need interfaces" vs. Multiple Inheritance and so on. There were two very good responses, one, a real "gem", by Marina Levit, an MVP who has a penchant for succinct and highly detailed instructional replies on the newsgroups, and another by "DeveloperX" - an unnamed but equally proficient poster. I reproduce them here:


Interfaces are meant for classes that have the same behavior, but different
implementation for that behavior.

For example, a Person object might implement a Move method one way - by

A Car object might implement a Move method another way - by driving.

However, a Person and a Car, have nothing else in common. They can't share a
common ancestor.

But they can both implement the same interface. And someone with a
collection of objects implementing this interface, can call the Move method
on each of them, without regard as to whether the object is a Car, a Person,
or something else. Because they all implement the same interface, they can
all be moved.

An interface is not a blueprint for a class. If you have only one class
implementing the interface, then you shouldn't have an interface. And if
you have multiple classes implement the interface, but they all have the
same implementation, then you should be using inheritence.


Interfaces also allow you to group areas of functionality which makes
developing simpler.

For example imagine a wheel object representing a wheel with a tyre on
it. You might expect to see methods and properties like , width,
height, tread pattern, spoke style, valve, inflate, polish, deflate,
tyremake, hubmake, tyremanufacturer, hubmanufacturer.

Now when you're programming against that wheel you're going to see a
huge list of properties and it might not be immediately clear what they

Now have a wheel object that implements IHub and ITyre things become
clearer. you know IHub.polish will polish the hub, previously you might
have inadvertantly polished the tyre. You can also now remove
tyremanufacturer and hubmanufacturer and simply have manufacturer on
each of the interfaces.


Open -Source ASP.NET 2.0 CMS (Content Management Systems)

I got interested in the current state of the ASP.NET 2.0 CMS system marketplace, mostly from the point of view of whatever is either source-code-available, or open-source. I have a post on the MS C# newsgroup about this and it looks like, from the initial response, that there are more than a few people who share my interest. I've already looked at about five of them, including Umbraco, axCMS, SharpNuke (a C# port of DNN that is faithful to the original VB.NET version and converts to ASP.NET 2.0 very nicely) and a couple others.

As I go on my travels looking at these, if anybody wants to post a suggestion of one that you like I'll be happy to review it.


1) Must be either open-source or a free non-restrictive "GPL" type license that allows you to modify the code.
2) MUST be either in ASP.NET 2.0, or can be easily converted.
3) Must be able to be deployed in a shared hosting account environment where you may not have direct access to either IIS or the desktop ( in other words, it is capable of "installing itself").

So far, Umbraco and SharpNuke look the most promising.

Iterating List <T>

A question popped up on the C# group that covered something very nicely:
How can you iterate (foreach) over a Generic List?

If you're using List<> then iteration should be fine - List<> has
GetEnumerator() defined.

Using a list

List<FooClass> MyList = SomeBarFunctionThatReturnsAList();

Foreach(FooClass foo in MyList)

If you're using a custom collection class that you made
yourself, then it needs to implement the IEnumerable interface, which
is a lot easier than it sounds.

To implement IEnumerable, you just implement GetEnumerator, and then you
get to play with the new "Yield Return" statement,which automatically
wraps the method in an enumerator object.

Using a custom class that wraps around a List<>

private List<FooClass> myList;

public IEnumerator GetEnumerator()
foreach (foo in myList)
yield return foo;

This message has been brought to you by the words Foo and Bar.


Visual Studio 2005 Service Pack 1 BETA


Did I say it's "BETA"? It is.

NOTE 1: Somasegar says this may be incompatible with Windows Vista.

NOTE 2: If you have the Web Application Project add-in installed, you must uninstall it first before applying the Service Pack. The pack includes the latest version of it, and will install it for you. See note number 4 for an issue where it "looks like" you've lost your Web Application Projects!

NOTE 3: As with many MS installations, this may sit near the end with "Time Remaining: 2 seconds" for up to 30 minutes or more. Just get over it and wait.

NOTE 4: There is an issue that WAP templates may not be installed correctly unless you run:

"c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" /InstallVSTemplates

Without this you could run into one of the following: If you previously had WAP you will get errors adding new forms from templates. If you didn't previously have WAP you may not be able to create a new WAP because the project templates are not visible. The /InstallVSTemplates switch causes the IDE to unzip the template zip files under the ProjectTemplates and ItemTemplates directories to the corresponding ProjectTemplatesCache and ItemTemplatesCache directories. When you install SP1 it should put the new zip files on disk. However, the SP1 installer is failing to cause the IDE to unzip them. It is possible that there is more to this in that the zip files may not be properly uninstalled when you uninstall WAP and/or the SP1 installer is not installing the new zip files. (according to Tim McBride of MS)

TIP: If you temporarily disable the on-access scan feature of your anti-virus software during the installation, it can speed things up.

Approx 371MB

All in all, if you look at the fix list over at the Microsoft Connect site, they've covered a lot of stuff.

Here is the "Fix List", which has been requested in a comment. This comes from the Connect site, which is Passport login only, but the download itself is public; I have no answer why they did this:

Fixes included in the Visual Studio 2005 SP1 Beta Service Packs
As always, the goal of Service Packs is to increase the overall quality of the existing product features while maintaining a high level of compatibility with existing applications.

Visual Studio 2005 Service Pack 1 Beta focuses on addressing product issues reported by customers since the release of Visual Studio 2005 and includes the following types of fixes:

The Hotfixes and General Distribution Release Updates released between Visual Studio 2005 Release to Market and the end of the Service Pack customer beta period.
Any fixes addressing security issues categorized by the Microsoft Security Response Center as "Critical", "Important" or "Moderate".
Fixes for product reliability and stability issues, including those reported by customers via the Product Feedback Center, and the crashes most frequently reported via Watson.
Fixes for the top customer and supportability issues as reported by Customer Support Services.
Fixes for common "eligible" functional issues reported by customers via the Product Feedback Center. "Eligible" functional issues are those that do not require breaking changes, architectural changes, or Design Change Request level feature work and that do not create unacceptable product quality risk and/or cost of implementation.
Hotfixes included in the Beta Service Packs:
Hotfix KB Article
Fix Description

Update to the Web Project Conversion Wizard in Visual Studio 2005

FIX: You receive LNK2001 and LNK1120 error messages when you use the Vcbuild.exe command-line tool to build a Visual C++ solution

FIX: The customized color code marker that is actually added may differ from the customized color code marker that you try to add in Visual Studio 2005

FIX: The IDE stops responding when you work with nested generic types in C# in Visual Studio 2005

FIX: A native application takes a long time to start when you try to debug the application by using Visual Studio 2005

KB911884 KB Info Not Yet Available

FIX: You may receive an error message when you rebuild a solution and try to view a Windows Form in Design view in Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

FIX: IntelliSense may stop working, and Visual Studio may crash, when you try to open a large Managed C++ project in Visual Studio 2005

FIX: The IDE stops responding when you build a project that generates lots of text in the Output window in Visual Studio 2005

An attributed ATL-based COM server unexpectedly exits in Visual Studio 2005

FIX: The browser may stop responding when you scroll through a Visual J# 2005 Web page that contains a J# Browser Control

FIX: Error message when you use the debugger in Visual Studio 2005 to debug an MFC class library application: "Managed Debugging Assistant 'Loader Lock' has detected a problem in ''"

FIX: You may receive Visual Basic compiler error messages when you are developing a Visual Basic 2005 project in Visual Studio 2005

FIX: Visual Studio 2005 may stop responding when you build a Web application project that is checked out of Visual SourceSafe

KB Info Not Yet Available

Update to support Visual Studio 2005 Web Application Projects

FIX: An access violation may occur when you try to run a Visual C++ 2005 application that contains OMG CORBA IDL code

FIX: Error message when you use certain code patterns that involve the IDisposable interface in the Visual Studio 2005 C++ compiler: "Fatal error C1001"

FIX: You may receive an incorrect error message when you open a Visual Studio 2005 Tools for Office document

FIX: All the applications that use the C run-time library may not start after you install Visual Studio 2005 and then you uninstall Visual Studio 2005 without restarting the computer

FIX: Error message when you try to use the Visual SourceSafe 2005 LAN booster service together with Visual Studio 2005 on a server that is running Windows 2000: "Unable to use SourceSafe LAN service"

FIX: The Visual Studio 2005 IDE stops responding when you work with a large Visual C++ .NET solution in Visual Studio 2005

FIX: The report does not print the first time that you click Print when you try to print the report from the Report Viewer control in Visual Studio 2005

FIX: The Visual Studio 2005 IDE may corrupt the deployment files for a Web Setup Project and for a Setup Project

FIX: The position of the Properties window may not be saved after you exit Visual Studio 2005 on a dual-monitor system

FIX: The Cole Property Page object of a Visual C++ application may be deleted when the Bound Property Changed function is invoked, and Visual Studio 2005 may unexpectedly close (crash)

FIX: Custom build steps may not run when you add the custom build steps to a Visual C++ 2005 Win32 static library project in Visual Studio 2005

FIX: Japanese, Chinese, or Korean characters in resource files may be overwritten by question marks after you convert a Visual C 6.0-based project to Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

FIX: You may experience performance issues when you use solutions that contain large Visual Basic projects in Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

FIX: The Atls.pdb file and the Atlsd.pdb file contain incomplete debugging information when you debug an ATL-based C++ application in Visual Studio 2005

KB Info Not Yet Available

FIX: A floating-point exception may occur when an inline function in a C++ application returns an uninitialized floating-point variable in Visual Studio 2005

FIX: You may experience slow performance and increased memory usage when you start the debugger for a Visual C++ project in Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

FIX: MS Project Work Item Publish Error

How to rebuild the C++ STL library for Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

FIX: You may receive an error message when you try to build a Web project that references a .NET Compact Framework 2.0 assembly in Visual Basic 2005

FIX: You may receive an error message when you consume an assembly that has an obfuscated generic type in Visual Studio 2005

KB Info Not Yet Available

FIX: You may receive a "Fatal error C1902" error message and a solution build may fail when you try to use the AT command or a scheduled task to automate a build of a C or C++ project in Visual Studio 2005

FIX: You may experience slow performance when you work with a Visual Basic solution that contains many projects in Visual Studio 2005

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

FIX: Visual Studio 2005 exits unexpectedly when you try to edit an existing Data Table object or add a new Data Table object to the dataset that you are editing

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available

KB Info Not Yet Available


Windows Vista RC2 - Build 5744 Out Today

Today Microsoft released what is expected to be the final build of Windows Vista to leave Redmond before the final RTM code. 5744, like its predecessor, is built on the final RTM source code branch.

My only issue with RC1 (x64) was that it couldn't perform an upgrade over a pre-existing Windows XP x64 edition. That meant I'd have to spend hours reinstalling various pieces of software, a luxury of time that I can't afford right now.

I installed the 32 bit version on a separate partition on my plain vanilla Gateway AMD Turion notebook, but it would not recognize the sound card, so I gave up.

The main issue with this stuff, at least from the 64-bit standpoint, is driver compatibility. The same thing happened with Windows Server 2003 and Windows XP x64 - the manufacturers were slow to arrive at first base with their 64-bit drivers. We will see how it goes this time, eh?


Note to Self: SET NOCOUNT ON, "NOT"!

I'm creating this web page for our Network Operations Center that allows them to test a specific mission - critical webservice that handles VOIP calls. It's basically a Web-based API for our internal Sip Proxy and Media servers, that I wrote. It allows any kind of device that can consume a standard WebService to use our VOIP Calling API.

So I've got like 30 different methods, and this page will iterate over every method, making a test call, and it populates a DataGridView with a new row that is colored green for success (with the results information) or red for failure, that includes any exception information, for every one of the methods in the test suite. So the guys in the NOC who need to have everything completely "idiot proof" can simply bring up this page, press the "Start" button, and watch it dynamically refresh as each method is called. All green, you are "OK". If you have a red row, you have a problem. If a method is supposed to do a database insert, and you get the wrong return value, you would also color it red, even though there was no exception.

So, I'm finishing method 25 of the 30 methods in the test page and it keeps coming up red. I know it works in the WebService itself because we've already tested it.

Finally I look at the stored proc it runs, and I see it:


Jeesh! This has been in ADO and ADO.NET since ancient times; when you make a SqlClient call such as ExecuteNonQuery, it returns an integer containing the number of records affected. Except -- when somebody put "SET NOCOUNT ON" in their stored procedure. You Database Folks, please don't do that unless there is a very good reason for it, OK? I couldn't find a single reason in this stored proc to have "SET NOCOUNT ON" - it was probably just force of habit for this person.

Rest my case.

N.B. I got a comment below indicating "surprise" that I should recommend this. For example, you may often see "optimization advice" that reads something like this:

"When you use SET NOCOUNT ON, the message that indicates the number of rows that are affected by the T-SQL statement is not returned as part of the results. When you use SET NOCOUNT OFF, the count is returned. Using SET NOCOUNT ON can improve performance because network traffic can be reduced."

The fact of the matter is, if you have a single row update on a single table, and you need to know if it succeeded, you are going to have network traffic whether you use an output parameter or whether you rely on ADO.NET's return value from having NOCOUNT off. The choice is yours to make, but the most important thing is that if the person who makes the call to the stored procedure isn't the same person who wrote it, and they haven't been properly informed or documented, you have a problem. It's a pretty safe bet to assume that the people who wrote ADO and now ADO.NET would not have put that feature there unless they expected lots of people to use it.