Asp.net debugging (inexplicable problem )!...

Source: Internet
Author: User

For a company to maintain the website, the boss asked to add a new module. The whole system was debugged locally and there was no problem. However, the following error is reported when uploading data to the server:

"/" Indicates a server error in the application.
--------------------------------------------------------------------------------
Name
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details: system. indexoutofrangeexception: Name
Source error:
An unhandled exception is generated during the execution of the current Web request. You can use the following exception stack trace information to determine the cause and location of the exception.
Stack trace:
[Indexoutofrangeexception: Name]
System. Data. Common. fieldnamelookup. getordinal (string fieldname) + 55
System. Data. sqlclient. sqldatareader. getordinal (string name) + 68
System. Data. sqlclient. sqldatareader. get_item (string name) + 10
Farmer. default1.page _ load (Object sender, eventargs E)
System. Web. UI. Control. onload (eventargs e) + 67
System. Web. UI. Control. loadrecursive () + 35
System. Web. UI. Page. processrequestmain () + 750
--------------------------------------------------------------------------------
Version: Microsoft. NET Framework Version: 1.1.4322.2300; ASP. NET version: 1.1.4322.2300

It took me a few days to find an error. The boss was so anxious that no result was returned. Finally, I had to include all the code in
Try... catch is in progress. I have not done any processing in catch, and somehow the error disappears. The boss has explained it. But the error is true.
The cause is not found yet. After two days of hard work, the error is finally found.
The original developer used the SQL statement "select substring (name, 1, 8), title from tablename" in the program,
The name field is not restricted during user data input.

There is no problem in local debugging because the data in this file conforms to this length and this exception is not triggered.

Conclusion: The reason why developers use such SQL statements is to make the display look good on the page, but they should not be processed in SQL statements,
My solution is to change the SQL statement to "Select name, title from tablename", and then, for the data of the retrieved Name field,
If the length exceeds 8, the request is intercepted. Otherwise, the request is not processed. The core problem is that the designer has missed the design of the database. Now the website is running with a lot of data, and I only have to take a compromise.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.