asp.net run prompt does not set an object reference to an instance error resolution for an object _ practical tips

Source: Internet
Author: User
Tags stack trace
Object references are not set to an instance of an object
One, the general statement on the network
1, the ViewState object is null.
2, Dateset empty.
3, the SQL statement or datebase causes DataReader empty.
4. When declaring a string variable, the variable is applied without null value.
5, the object is not initialized with new.
6, the Session object is empty.
7. When you assign a text value to a control, the value does not exist.
8. When using Request.QueryString (), the acquired object does not exist or the initial value is not assigned when the value is empty.
9, when using FindControl, the control does not exist but does not do preprocessing.
10. Duplicate definitions cause an instance error that does not set an object reference to an object.
Two
(1) The variable being set is NULL or does not have a value, typically occurs when passing parameters, and also occurs when using data controls such as the DataGrid or GridView or DataList.
(2) The control name does not correspond to the codebehind inside
(3) Initialization of object not with new
(4) The control referenced in the program does not exist
Workaround:
(1) Use Try ... Catch...finally catch the error, or output the variable value directly with Response.Write ()
(2) To see if there are any uninitialized variables in the code
Third, Sqlconnection.open does not set object references to an instance of an object
Sometimes the open () method of the SqlConnection object appears when the ASP.net program is developed using VS2003
An object reference is not set to an instance of an object.
Note: An unhandled exception occurred during the execution of the current Web request. Check the stack trace for more information about the error and where the error occurred in the code.
Exception Details: System.NullReferenceException: Object references are not set to an instance of an object.
SOURCE Error:
。。。。
Conn. Open ();
......
Tracking debugging can definitely determine the new operation on Conn but the program often complains in this place, but sometimes restarting the server or restarting IIS is working. How to debug also can not find the problem so this time may be installed on your computer. Netframeework framework is problematic and may not have SP1.1 patches installed
Need to play net reprinted from the Http://www.oh100.com Network, please keep this mark Frameework1.1sp1 patch, to Microsoft's official website download after installation will be good.
Four, the general occurrence of nullreferenceexception abnormalities of my personal summary has the following:
1. The namespace in which the object resides is not referenced
2. No instantiation of Object
3, an exception occurred, the instantiation failed object is null
When IIS can't carry it, the above error will also appear.
An error occurs when the application's user access exceeds the range it can afford.
Improve your programs, use caching, and minimize the number of interactions with the database.
Six, I encountered the problem is, did not intend to reset the dataset reference, after this problem, please check your own code, is not in the other place, the dataset in my program is set to the global object.
When you find that all the methods are not working, hit the. NETFramework patch
Eight, I appear this error, just because the site inside the DAL DLL file invalidation, business layer instances can not idal inside the object
But it's a waste of the afternoon on the code.
Nine
For each suspicious place to add monitoring, at first thought it was the SQL statement was wrong, checked several times, to exchange SQL statements or reported the same error. According to the results from Google, the reference to object redefinition can cause such a result. According to this hint, replace the page-level global object, finally finished.
classdboper{
/* constructor has no function body
**c# write a series of methods to manipulate the database
* * Initially for the sake of convenience, as little as possible to declare the object, only in the global declaration of a Privatedboperdb=newdboper (), in different ways to invoke the object's methods to avoid the definition of the memory waste. Later, the code refactoring, in the compile time did not error. But when it is run, "NullReferenceException: An object reference is not set to an instance of an object" appears. The result was a couple of hours of it. Later, according to Google's results, the different methods used in the Dboper object one by one to redefine the local variable (a method that only defines a Dboper object, multiple calls its methods are normal), remove the global private variable. It's normal to run again.
It's not clear why the custom object was raised as class for private use in different ways.
Related Article

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.