1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Weirdest programming problem I've ever seen in 10 years, SQL query returns no records

Discussion in 'C#' started by aab1, May 28, 2011.

  1. #1
    This is by far the weirdest thing I saw in 10+ years of programming. On my website users have accounts (in the Users table) and can add items in their account (in the Items table)

    I use this to get their list of items when they are logged into their account:

    Query = "SELECT * FROM Items WHERE Username = '" & Request.Cookies("onlineuser") & "' AND Deleted = False ORDER BY " & SortOrder & " DESC"
    Set RS = conn.Execute(Query)

    This worked for a year for everyone until one particular user signed up, he says the items he adds don't show up in his account and RS.EOF is true on that query when he logs in even after adding items. I've also made sure his items aren't marked as Deleted. Strangely, if he tries to add the same item again he gets an error that it's already in his list.

    So why does the query work for every single user but one?

    This doesn't even seem possible, I just don't get it.

    Edit: even deleting and recreating the account doesn't help. his username is like user_12 would that cause any conflicts?
    Last edited: May 28, 2011
    aab1, May 28, 2011 IP
  2. RonBrown

    RonBrown Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    The first thing that springs to mind is that he has cookies switched off or that the cookie information is not available (or set).

    To solve this problem I'd add a bit more error checking first such as

    1. Makes sure the parameters exist i.e. makes sure request.cookies("onlineuser") is populated. If not, return an error message
    2. Do this for all parameters
    3. Add in error checking for rs.eof, so if an empty dataset is returned, write an error to the page with the SQL string and other relevant data and ask for the message to be returned to you.

    It's only by doing this that you will get to the bottom of the problem.

    You need to add error checking in as part of your everyday programming. You can never assume that the data you are expecting such as request.cookies will actually return anything so you need to be able to deal with situations where this happens.
    RonBrown, May 29, 2011 IP
  3. aab1

    aab1 Member Affiliate Manager

    Likes Received:
    Best Answers:
    Trophy Points:
    Thanks, I finally figured it out last night. I knew it wasn't the cookie as the first thing that asp page does is kick you out if the cookie is not set.

    It turned out it was the SortOrder that was blank, I had just added a new feature to custom sort the list and have your sort order saved in your user record in the DB. Turns out I wasn't properly checking for a null field which it was for this user and therefor the sort order was missing. I made the null field validation proper for the SortOrder check and it defaults to default sort order if the user does not set a custom one.

    It strange that only one out of about 700 users would have reported this.

    Thanks for the help
    aab1, May 29, 2011 IP