473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tale of debugging and programming logic in c#/sql


Just finished off a production .NET web application written in c#.

I set up a error handler in the global.asax which is triggered to iterate
through the error stack and send it and other information to me in an
email. This gives me logging and alerting and a record of usage ( by
sending time ).

After deploying the application I noticed intermittent errors in the Page
Load event after the user logs on. I wasn't every user, but the errors
occurred all day long. My error handler email shows two session variables
and the user name as well as the trace. The error was: Object reference
not set to an instance of an object. If you've done any .NET, this can
mean an uninitialized or null variable ( among other things) that is being
used in a method or cast that a NULL cannot be used.

I was puzzled. This would have been the very first thing after Forms
Authentication -- and obviously, I would run through that step many many
times both in the VS IDE and in QA. Occasionally my QA engineer would see
the problem, very infrequently, and report it to me. But then I could
never reproduce it. And by the time I got back to him and asked him to
show it to me, the problem didn't reappear.

Then I noticed something. All the user names were multiwords -- that is, I
was always testing with something like /jb/ or /jbailo/ as the user name.
In the error messages, the user name was Mary S. Rutherford. And the spec
said we would allow for a full name as the username. Aha! I have found the
bug -- spaces and periods. To test, I entered my name, John A. Bailo and
it threw the error. So I set up a parsing method to remove all
non-alphanums from the user name. Testing again, I saw that my fix worked
and I pushed it to production. I was anxious to find a fix, and I didn't
do full testing. The login page was written poorly -- it was from an
earlier release of the web application -- but we didn't have time to change
it. It used a composed String for the SQL command rather than a
parameterized query.

Waited a few hours and watched the errors. Nope. The production site was
still generating errors. What was it, what was it??? Finally, I loaded up
VS.2003 and set some breakpoints. Instead of using my name, I used one of
the names from the customers. BOOM! Now I saw it. The login page does a
INSERT if its a new user ( and a lookup if its a returning user). When the
INSERT statement ran with the user's name, it threw an error that said
'String or binary data may be truncated'. That's it. The spaces aren't
the problem -- it was that the user name was TOO LONG! Checking the
database, I see that yes, the username field was nchar(10)! Inserting a
longer name threw the error.

So what happened was: there is a Session variable that is created once the
user authenticates or creates a new login name -- it is based on an ID
number generated in the database once the user's name and password are
inserted. The INSERT never completed and so caused the session variable
to be NULL and the first time it was accessed by another method -- it threw
the error.

Why was I fooled? Because John A. Bailo with the spaces and period removed
is JOHNABAILO -- 10 characters!!! I /fixed/ the problem, but locally --
not globally; only for people whose whole name is 10 chars or less after
removing spaces and non-alphanums!

Oh, and why didn't the error email show the actually error? Because I had
used a try/catch block for the login INSERT statement -- and I didn't put
tracing or logging in the catch -- thus the statement threw an exception
and proceded on its merry way -- and later on in the code when the missing
session variable threw an error -- I had no idea what the actual cause was
-- though I spent a week trying to fix it with system level fixes such as
explicit garbage collection and tweaking the IIS server.

Oh -- the logic of programming... :D

--
W '04 <:> Open
Nov 16 '05 #1
1 1700
I've recently learned about NUnit.org. Learning to use it correctly
is the next objective.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Irritable Bowel Syndrome" <ja*****@earthlink.net> wrote in message
news:J0*****************@newsread1.news.pas.earthl ink.net...

Just finished off a production .NET web application written in c#.

I set up a error handler in the global.asax which is triggered to iterate
through the error stack and send it and other information to me in an
email. This gives me logging and alerting and a record of usage ( by
sending time ).

After deploying the application I noticed intermittent errors in the Page
Load event after the user logs on. I wasn't every user, but the errors
occurred all day long. My error handler email shows two session variables and the user name as well as the trace. The error was: Object reference
not set to an instance of an object. If you've done any .NET, this can
mean an uninitialized or null variable ( among other things) that is being
used in a method or cast that a NULL cannot be used.

I was puzzled. This would have been the very first thing after Forms
Authentication -- and obviously, I would run through that step many many
times both in the VS IDE and in QA. Occasionally my QA engineer would see the problem, very infrequently, and report it to me. But then I could
never reproduce it. And by the time I got back to him and asked him to
show it to me, the problem didn't reappear.

Then I noticed something. All the user names were multiwords -- that is, I was always testing with something like /jb/ or /jbailo/ as the user name.
In the error messages, the user name was Mary S. Rutherford. And the spec said we would allow for a full name as the username. Aha! I have found the bug -- spaces and periods. To test, I entered my name, John A. Bailo and
it threw the error. So I set up a parsing method to remove all
non-alphanums from the user name. Testing again, I saw that my fix worked
and I pushed it to production. I was anxious to find a fix, and I didn't
do full testing. The login page was written poorly -- it was from an
earlier release of the web application -- but we didn't have time to change it. It used a composed String for the SQL command rather than a
parameterized query.

Waited a few hours and watched the errors. Nope. The production site was
still generating errors. What was it, what was it??? Finally, I loaded up VS.2003 and set some breakpoints. Instead of using my name, I used one of
the names from the customers. BOOM! Now I saw it. The login page does a INSERT if its a new user ( and a lookup if its a returning user). When the INSERT statement ran with the user's name, it threw an error that said
'String or binary data may be truncated'. That's it. The spaces aren't
the problem -- it was that the user name was TOO LONG! Checking the
database, I see that yes, the username field was nchar(10)! Inserting a
longer name threw the error.

So what happened was: there is a Session variable that is created once the user authenticates or creates a new login name -- it is based on an ID
number generated in the database once the user's name and password are
inserted. The INSERT never completed and so caused the session variable
to be NULL and the first time it was accessed by another method -- it threw the error.

Why was I fooled? Because John A. Bailo with the spaces and period removed is JOHNABAILO -- 10 characters!!! I /fixed/ the problem, but locally --
not globally; only for people whose whole name is 10 chars or less after
removing spaces and non-alphanums!

Oh, and why didn't the error email show the actually error? Because I had used a try/catch block for the login INSERT statement -- and I didn't put
tracing or logging in the catch -- thus the statement threw an exception
and proceded on its merry way -- and later on in the code when the missing
session variable threw an error -- I had no idea what the actual cause was
-- though I spent a week trying to fix it with system level fixes such as
explicit garbage collection and tweaking the IIS server.

Oh -- the logic of programming... :D

--
W '04 <:> Open

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed_P | last post by:
Hello I just wanted to get the opinions of those of you who have experience developing C# applications and programming in general. I currently am learning the basics of programming (choosing C#...
1
by: Microsoft | last post by:
I am trying to add asp.net data based functionality to a html template that includes Dreamweaver Fireworks-based fly out menus. Things seem to run OK running through a browser but the doing...
42
by: Kevin Spencer | last post by:
Is it just me, or am I really observing a trend away from analysis and probem-solving amongst programmers? Let me be more specific: It seems that every day, in greater numbers, people are coming...
14
by: GUSTAVO V. P. | last post by:
Hello, my name is Gustavo and I want to know: What one needs to be a good programmer of computers? Which your advice are to be a good programmer? How is the logic acquired? Is it true that...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
5
by: John Henry | last post by:
I am back against the wall trying to migrate my multithreaded application from Python 2.3 to 2.5. The part of the code that's failing has to do with queues (2.3 queues and 2.5 queues are not the...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.