On VB

My Biggest VB Programming Mistake

When "Oops!" becomes "OMG!" On VB columnist Joe Kunk shows how a simple oversight when using SQL Server 2000 Data Transformation Services (DTS) nearly ended in disaster.

Like all developers, I make mistakes, lots of them. Fortunately they are usually minor mistakes that are easily detected and corrected. I have made all the common mistakes like forgetting the NOT operator, using an OR instead of an AND, plus slightly more serious mistakes like neglecting to handle multi-user concurrency checking, performing deletes when I meant to do updates, and spending days to develop a feature only to find the customer really didn't want it after all, and so on.

One of my biggest programming mistakes was listed as Trap #1 in the On VB article "5 Traps to Avoid in Visual Basic." In short, I had made the mistake of declaring the user identity as a Visual Basic module-level variable in an ASP.NET application, setting the Web application identity for all of the Web application users to be the same as the last authenticated user. This had the undesirable result of expectantly displaying other users' information. I neglected to do multi-user testing and it went into production. Fixing it was easy; I stored the user identity in Session. See the article for more traps to avoid in Visual Basic development.


Another of my biggest programming mistakes was actually not a coding mistake at all but a failure to fully understand one of the tools I was using. In this case, the tool was SQL Server 2000 Data Transformation Services (DTS).

I was working to provide executives with the ability to view production Human Resources data ad-hoc via Microsoft Query. To make the data more understandable and lessen the chance of a misinterpreted query, I created several flat views of the data for primary dimensions like employee, location, fiscal period, etc. Following procedure, I created the views on the test server and scripted them onto the production server. The executives liked the ability to dynamically query these views and then asked for several more.

I created the new views on the test server and when finished, I needed to implement the new views and a couple updates to the old views onto the production server. Rather than script the views, I thought it would be faster to use the DTS Import/Export wizard (Figure 1) to copy the views from the test server to the production server.


[Click on image for larger view.]
Figure 1. Opening screen of the SQL Server 2000 DTS Import/Export Wizard.

Working my way through the wizard screens, I came to the "Select Objects to Copy" screen shown in Figure 2. My selections on that page completed exactly as shown. Notice the highlighted option "Include all dependent objects" that is checked by default under the Create Destination Objects checked option. Copy all objects was not checked and the desired views had been individually selected with the "Select Objects... " button.


[Click on image for larger view.]
Figure 2. The SQL 2000 DTS Import/Export Wizard Select Objects screen.

See the problem? By leaving the "Include all dependent objects" checked, when it deleted the existing destination views, it deleted the dependent objects of the Views which were the tables themselves. My attempt to copy a couple views into our most critical database actually resulted in dropping and recreating the source tables from the database while they were in use in production. I was caught totally off guard; less than 5 minutes later we received several calls from HR that they were no longer able to see employee data in their main application. Truly, "Oops" becomes "Oh My God!" at that point.

How did I fix it? Fortunately due to the criticality of the database, we had nightly full backups and transactional backups running every 2 hours. This error occurred only 20 minutes after the last transactional backup. We restored the last full backup and applied the transactional backups to get within 20 minutes of the error. The users were able to identity and re-apply the updates for those last 20 minutes. Subsequently I refused to use the DTS Import/Export Wizard ever again and I always generated scripts to create or update test objects on the production server after careful review.

Lessons Learned
Most developer mistakes are minor; a few are not. The lesson I learned from these incidents is to stay alert and remain fully aware of what I am doing, even during mundane tasks. What programming mistakes have you made and how did you address them?


About the Author

Joe Kunk is a Microsoft MVP in Visual Basic, three-time president of the Greater Lansing User Group for .NET, and developer for Dart Container Corporation of Mason, Michigan. He's been developing software for over 30 years and has worked in the education, government, financial and manufacturing industries. Kunk's co-authored the book "Professional DevExpress ASP.NET Controls" (Wrox Programmer to Programmer, 2009). He can be reached via email at joekunk@ajboggs.com.

Reader Comments:

Mon, Aug 8, 2011 longstrd Florida

I like reading the articles in VS mag. While reading new coding items is useful, reading tips and tricks it useful. I do not often read the comments, these comments are an example of why not. Too bad. Some of the comments that were added had some interesting insight. I am surprised at the Off Topic comments. I think that for Mr. Kunk to prompt folks to share their mistakes could of lead to a very useful log of items to look out for and the idea that Yes, there are Solid Safe practices, however we all make . . . mistakes. Even the most experienced.
Thank you; to those who did share their experiences as well as add some interesting information.

Thu, Mar 10, 2011 Peter Vogel Canada

Great article. I make a very good living programming in C# and VB (and, before that, in PL/1, COBOL--I'm very old). At some point you realize that the tool doesn't matter: your only real tool is your brain. Amazing that so many people (who, you'll notice, read the VB article) haven't realized that yet. They're young--they'll probably learn better. There are, in fact, two differences between C# and VB. First, C# developers feel a program should end with }}}}}}; VB programmers feel it should end with End If/End Next/End Sub/End Class. Second, because demand still outstrips supply, C# programmers get paid about 10% more--a tradition that I'm happy to maintain with my C# clients.

Tue, Mar 8, 2011 LostInSpace

Nathan wrote: "In any field, true professionals very seldom judge anyone by the tools the use" Yes on that - I'm a hardware guy who writes a lot of software in whatever tool is most useful. But the "Real Software" guy's are always around complaining about this language or that language. Somehow I manage to write 10 times as much useful code as they do, and I don't complain about any tool. Just get the job done...

Fri, Mar 4, 2011 Nathan 4WT4

My hobby is 3D graphics a& I see the same kinds of foolish comments in that field as I see here from some of the C#ies. Usually they fall into two categories. 1. Established folks who invested a lot of time in learning high-end apps put down the newer user friendly tools that can often produce comparable results without the learning curve. 2. Newbs who haven't the beginnings of enough experience to make valid judgements but they think they're cool because they can do the basics in package A. In any field, true professionals very seldom judge anyone by the tools the use, or allow their own prejudices to make them sound like fools. They use whatever gets the job done.

Tue, Mar 1, 2011 Bruce A. Walker Ohio

I can't believe that C# programmers are still beating that dead horse! Microsoft as early as 2001 in the Tech Conference for Great Plains made it clear that the C# and VB would "co-evolve" and that both would do the same thing resulting in the same MSIL code. And for the most part they kept their promise with the exception that VB left C# in the dust for the first 5 years. By VS 2008 they have the two languages almost equal and claim that VS 2010 now levels the playing field and neither language will be allowed to out pace the other; yeah the developers are actually working together now. So all you pompous C# guys need to listen to what Microsoft has been saying for TEN YEARS! It's all just syntax now. And sorry, you are NOT C programmers; I programmed in C in the DOS world and can tell you C# isnt' even close! And incidently, I have projects in both VB and C# and frankly I love whichever language I happen to be using at the time.

Mon, Feb 28, 2011 James

Gents the whole language holy war is Off Topic and really doesn't belong here. Briefly, I'd also state that every programming language to date has been created for a reason and to discard it as useless out of hand is to take the fool's path. So ease up, sit back, and stop rejecting things just because they are either unfamiliar or not as comfortable FOR YOU as your chosen language. The bottom line is always does it get the job done with acceptable results and a reasonable ROI. BACK ON TOPIC... This mistake can really be made with any tool, so automatically bashing DTS is bad, too. Ever accidentally run a script against the wrong server when working with multiple windows under time pressure? I know I have. Fortunately, I've also developed the habit of taking backups immediately before making major changes so there was little harm done. Good article, Joe. I wish more people would look at the bigger picture you're presenting.

Sat, Feb 26, 2011 Robert Swan

As others have commented, these were programming not language errors. But, like all such posts, if they only make one person stop, think, and catch an(y) error they have served well. On the 'my language is better war' (running since before Fortran vs COBOL) there must be several doctorates available for people to analyse how much, and why, Web space is wasted churning the same pointless debate. The best tool for the current task is not just the language but all the support,available experiance, and resource costs you'll need.

Fri, Feb 18, 2011 PJ

Lesson 1 - DTS is for DATA transformation not the data definitions - to move views use scripting.

Thu, Feb 17, 2011 Developer / SQL Dude Ohio, USA

And your /other/ SQL mistake... not understanding the capabilities of the fully-logged recovery model. In this example, you had a good backup chain, but you didn't take make a tail log backup, which would have let you recover to the second prior to your drop commit. IE, if you had manually run one more transaction log backup, that would include all the logged activity up to (and past) the failure, you could have done a point-in-time restore to just prior to the drops.

Thu, Feb 17, 2011

Wow! I have been coding since 3GL was the new coding environment. Nice to see the enthusiam and committment is there with GUI making things so much easier.

Thu, Feb 17, 2011 David Beautiful Ozarks

Rules to live by 1) You don't spit into the wind. 2) You don't tug on Superman's cape. 3) You don't pull the mask off the ol' Lone Ranger. 4) Don't mess around with DTS

Thu, Feb 17, 2011

I just wanted you all to know, my d*ck is bigger than yours.

Wed, Feb 16, 2011

Nearly everything you can do with C/C++/C#, you can do with a variant of VB. The only real difference (aside from the sheer amount of coding involved with C_ vs VB_) is how quickly data is processed. That, and VB is geared for drag and drop interfaces. VB variants suck at processing large amounts of data. C variants process the data faster, but you're looking at having to write far more lines of code to do it with. However, from a vast amount of personal experience, I seriously question why any real programmer would resort to using C/C++/C# for non-system vital applications, when the most effective method for creating a quick interface (hands down) is VB. And if you can't be bothered with common sense on how to write an effective algorithm to process data at a decent speed, ffs, use ASM to create a back engine.

Wed, Feb 16, 2011

Suck it VB Programmers.

Wed, Feb 16, 2011 Paul Kimmel Washington Monument

VB and C# comparisons pointless. Great article Joe. Perhaps a good follow would best practices for avoiding these kinds of mistakes.

Wed, Feb 16, 2011

Seriously, is anyone still developing with MS products?

Tue, Feb 15, 2011 GGardner Austin, TX

I got my certifications in C# and see some (few) benefits over VB. (Please give us the “yield” keyword in the next release!) That said I spend most of my time in VB. Now my company is moving to C#, partly at my urging, and I hate to think if I program mostly in C# will I become one of the pompous C# a-holes like those that commented here? VB serves as a great whipping boy for the insecure who need to put someone down so they can pretend they are superior. I hope VB lasts for many generations just to irk the pretentious. LONG LIVE VB!

Tue, Feb 15, 2011 Joe Kunk Okemos, MI USA

Thank you for all the comments. I always enjoy a good religious war, I mean, debate. For the record, I code in both Visual Basic and C#, depending on the specific needs of the application. I find it easy to switch between the two. I favor Visual Basic because I find it more expressive (not to be read as verbose), and I have been coding in some form of BASIC for more than 30 years. That said, I am not upset or disappointed if I am asked to code in C#; both languages have their strong points. I respect and admire talented developers from both camps. Regarding the article focus, I agree that it is mostly about SQL and not Visual Basic. But they are my two worst developer experiences to date. I very much enjoy sharing my experiences, even ones like these that are a bit embarrassing. It is good to be reminded that we are all human and fallible. Writing only about language syntax and features can get a bit boring, even for me. There is much more to being a successful developer than just language constructs and efficient algorithms. I will strive to continue to explore language and non-language issues and topics relevant to being a great developer, with humility and humor whenever possible. I sincerely appreciate all the comments whether you agree with me or not. I am simply glad to have you join in the dialog. Thank you.

Tue, Feb 15, 2011

This article should be title - "My Biggest Mistake is VB Programming" - not just these days, ever.

Tue, Feb 15, 2011 Robert Ontario, Canada

Biggest mistake... using VB Technically yes they do get compiled down to the Intermediate Language. But how do you know that they both translate into an equal set of MSIL code? I am sure there are situations where one language generates more code than the other. That's not to say one is superior but at least do the research before you claim VB and C# are equal. My main reason for hating VB is that it ruins coding habits and makes you lazy. I don't need to list reasons here as most of them have been mentioned already. C# is more portable, as it uses the C nototion. Once you learn it you can easily transition to C,C++,Java,PHP, and even PLSQL(Oracle). I know all of these languages and I work with them daily. It makes my job so much easier when working with almost identical syntax. As for ASP classic, even though it uses a vb syntax, I find it give you much more control over how a page is rendered than ASP.Net. My issues are that it is difficult to debug and many of the issues could have been avoided had a compiler been involved.

Tue, Feb 15, 2011 Narud Shiro Mexico, Mexico

Doesn't matter how many big mistakes you make, you can keep your head safe and in place as long as you don't make the mistake of forget the gold's rule: Always make and test backups.

Tue, Feb 15, 2011 SeeCoolGuy

just because it has a GUI doesn't mean anyone can use it. Another thing you mentioned is that you had backups for both full and transactional... had you ran a transactional backup immediately after your mistake, you could have restored all the data right up to the minute before your error. Never send a developer to do a dba's job.

Tue, Feb 15, 2011 Alberto Apu CRI

man: you MAJOR mistake was TO USE VB, that's all. It is NOT a languaje and no programmer should use this piece of shit. IF THEN ELSE ENDIF? who the hell invented that silly thing? have a nice day.

Tue, Feb 15, 2011 George the Dragonslayer

To all the C# users who think their language of choice is better. S#¤k #¤s - it's the same language as VB.NET only slower to type. All the code is compiled to the same instruction set in the CLR. So learn C++ and then come back and disrespect C# and VB.Net. Dumbasses!!!

Tue, Feb 15, 2011 frits

Ha Ha. 2 Comments bashing VB and 10+ comments from VB fanbois complaining about "so many" C# developers commenting. Cbuttic!

Tue, Feb 15, 2011 Ken

I still use VB6 and ASP Classic everyday, maintaining 12 year old desktop and web applications. New modules are still written in VB6. Customers still pay good money to download and use these products. When you own your own business, what makes sense is return on investment. Do you think I have gotten my moneys worth out of VS 6? Do my customers really care what programming language I use? I am sure that the time is coming when the VB6 runtime will not be supported and I will be forced to migrate to dotnet. Until then, I will keep using what pays the bills.

Tue, Feb 15, 2011 bobt

I appreciate the honesty of this article. It's not that we sometime shoot ourselves in the foot. We all do from time to time. The problem is the arrogant individuals who think they have all of the answers because they know a particular language. By thus becoming myoptic, they are left with developing a great profeciency in the reloading process so they are able to shoot themselves in the foot faster and more often.

Tue, Feb 15, 2011

If most vb programmers would leave option strict and option explicit on, I imagine it would have a different rep. Its the laziness and subsequent incompetence of VB devs(not all but quite a few) that have ruined peoples opinion of the language and those who use it. Lets just cast this random object to an int because the language doesnt care and will do it for me and not worry about the huge memory footprint and extra cpu time it takes to do it. Or i could learn something about things work and write effecient code. VB is good for macros and mockups, anything beyond that should be done in a proper language, by people who know what they're doing.

Tue, Feb 15, 2011 akman

It's amusing to hear C# boys act like they use the same language as their big brothers who know C++. The truth is that C# is simply VB with C notation. I know both, use both, and find VB slightly easier to maintain because it is slightly more verbose. What matter is not the language but the man or woman using it. Good VB.NET code is infinitely preferable to some of the crap I have seen foisted on the world by people who thought that using C# made them into real programmers.

Tue, Feb 15, 2011 NJ Coder New Jersey, USA

I've been a VB programmer since VB DOS 1.0.All you C - I guess you enjoy making the internals of a computer work more than you like mking your process work. VB net rocks... Everyprogrammer and every language has it's issues - Never trust DTS on a live database without beating it to death on a test database.

Tue, Feb 15, 2011 SC

First off good article, I appreciate the cador. I love it when people bust on VB. We made a lot of money building commercial software used by tens of thousands of people all in VB. We did it faster than anyone else could by focusing on producing useful products instead of worrying about figuring out how to use all the latest and greatest language features available in language x. So continue to feel superior about your language choice c# guys, I'll be on my boat enjoying the money we made by actually getting things done :)

Tue, Feb 15, 2011 Dave Mac Indianapolis

Wow! So many arrogant C# people in here. I like C# just fine and I develop in VB.net as well. There are advantages/disadvantages to both languages depending on the type of development one is doing. So get over yourselves. That said, I made a similar mistake with DTS by exporting views like the author resulting in production tables blown away. Fortunately the previous night's backup saved my behind. :)

Tue, Feb 15, 2011 KeyWestDan Key West, FL

My first SysAdmin job I wanted to use an old NT server to do backups as I didn't think the tape system was working. I noticed the NT box had a bunch of users and being new I didn't realize it was reading Active Directory rather than old users on the NT box. So I highlighted them all and deleted them, and every account from our main Active Directory. The previous SysAdmin had them update immediately and there was no other backup. Turned out the tapes had all failed back many months before I got there. Lots of fun restoring everything. Plus it was setup to remove the mail directories and everything else right away. Never knew an old NT box could wipe out the entire active directory.

Tue, Feb 15, 2011 Daniel

My biggest mistake in VB: Not trusting the manual and trusting the manual :) Not trusting the manual: Just started VB programming, and a bug crept up in a connection to an SQL Server database in code that had been ported from an Access DB connection. A "friend" who taught VB6 at the University of Texas told me it was a simple problem and started to debug, ignoring the error messages... and after 3 hours told me that we would stay there until it worked. I got my mind out of a rut, re-read the IDE error, Read the manual and the error messages, checked with MSDN, changed a constant that ADO did not like and got the program to compile 4 minutes later. Trusting the manual: MSDN VB section said that you could not call any low level FTP connections with callbacks from VB, this could only be done with VC++ or by using an external library. Check out on how it was done with VC++ on the MSDN VC++ section seeing if it was "hackable", one of the C programmers posted an example code in C++ and "If you want to do this in VB6, this is how to code the API link and manage the callback" - with a snippet of VB to boot :)

Tue, Feb 15, 2011 wildcard-star UK

Lots of C# lovies in here! I would just like to say that with the CLR in .net they do exactly the same things :) later...

Tue, Feb 15, 2011 Geoff Scotland

Wow, amazing how someone learns a language with a 'C' in it and they think they are omnipotent. C# is a relatively new language in computing terms, albeit rather good, but I wouldn't dirt VB/VB.NET which has been the mainstay of millions of programmers worldwide for many years. I think the author had real guts to reveal this information and that is something that you don't see too often in development terms, usually because ego's get in the way.

Tue, Feb 15, 2011 Matthew Sydney

To be a good .net programmer these days, you need to be fluent in both C# and VB.NET syntax. VB was my first love and we got married when VB.NET came out, but then I divorced for a more modern younger and sophisticated programming language call c# :)

Tue, Feb 15, 2011 wibbler

I can't believe people are still bothering to post comments on the lines of "my programming language is better than yours" (with the obvious implication that "I'm therefore better than you")... have to agree though that neither example has anything to do with VB.

Tue, Feb 15, 2011 Mr Pink Dublin

Tue, Feb 15, 2011 - "The only practical difference between C# and VB is syntax." Errrmm if you really believe this then you yourself are a mistake waiting to happen.

Tue, Feb 15, 2011

What do either of these total 2 mistakes have to do with VB ? The first is about application logic, and the second about the use of MS SQL Server. P.S. The only practical difference between C# and VB is syntax.

Mon, Feb 14, 2011

I think the real lesson here is to first test your solution, and then test your deployment. Seen too many great projects fail because everyone got excited about the code, and totally ignored how it was getting into production. BTW - scripting can vbe just as dangerous if you select 'script dependant objects'... caught one of my guys doing that a couple of years back, he'd failed to notice that the start of his script dropped the entire user database!

Mon, Feb 14, 2011

I don't know

Mon, Feb 14, 2011 Mr-Yellow

Mistake #1: Using VB. I had to go back to VB to do a project in recently after years of using other languages. It takes 5 times longer to code with all it's "Office paperclip" moments.

Mon, Feb 14, 2011 DrSchizo

My biggest mistake with VB: trying it thinking it was a programming language.

Mon, Feb 14, 2011 Leeds

Nice work.... Whilst working as a student placement on my uni year out, I managed to update our biggest client's (and one of the top five of their kind in the UK) 'customers' table to have all their clients as to be the same - that was over 100,000 records! Backups, transaction logs and a meeting with the MD later and it was all fixed! Thanks to our IT team for that! Client went ape-shit as you'd expect, lesson very quickly learnt! I even got asked back full time after finishing my degree!

Mon, Feb 14, 2011

Wow, use scrips, run scripts directly and you should see what you really doing...

Mon, Feb 14, 2011 C# guy

Programming in VB itself is a mistake these days. There you have it...

Mon, Feb 14, 2011 SQL John Scotland

Wow! you are recounting, word-for-word, the exact same experience I had when I was still wet behind the ears. I managed to kill a production database with approx 50000 new jobs a month. I got such a fright that day that 11 years on, my heart still flutters every time I see or hear of Enterprise Manager (cringe)

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above