Object reference is not set to the instance of the object -- Summary of possible problems, instance --

Source: Internet
Author: User

Object reference is not set to the instance of the object -- Summary of possible problems, instance --

I. general statement on the network

1. The ViewState object is Null. 2. DateSet is empty. 3. DataReader is empty due to SQL statements or Datebase. 4. When a string variable is declared without a null value, the variable is applied. 5. The new initialization object is not used. 6. The Session object is empty. 7. When you assign a text value to the control, the value does not exist. 8. When Request. QueryString () is used, the obtained object does not exist, or the initial value is not assigned when the value is null. 9. When FindControl is used, the control does not exist but is not preprocessed. 10. Repeated definitions may result in an error in setting the object reference to an instance.

 

 

II,

(1) If the set variable is null or the value is not obtained, this problem usually occurs when the parameter is passed, or when data controls such as DataGrid, gridview, or datalist are used.

(2) The Control name does not correspond to that in codebehind.

(3) The new initialization object is not used.

(4) The control referenced in the program does not exist.

Solution:

(1) Use try... catch... finally to catch errors, or directly use response. write () to output the value of the variable.

(2) check whether there are uninitialized variables in the code

 

 

III,

SqlConnection. Open has not set the object reference to the instance of the object.

When using VS2003 to Develop ASP. NET programs, sometimes the Open () method of the SqlConnection object appears.

You have not set the object reference to the instance of the object.

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. NullReferenceException: object reference is not set to the instance of the object.

Source error :....

Conn. Open ();

......

Tracking and debugging can certainly determine the new operation on conn, but the program often reports errors in this place, but sometimes it can be used properly by restarting the server or Restarting IIS. The problem cannot be found for debugging. In this case, it may be installed on your local machine. net frameework framework is faulty. It may not be necessary to install the NET FRAMEEWORK1.1 SP1 Patch. Download and install it on the official Microsoft website.

 

 

IV,

In general, the NullReferenceException exception occurs. I personally summarize the following situations: 1. The namespace where the object is located is not referenced. 2. The object is not instantiated. 3. An exception occurs. The instantiation failure object is null.

 

 

V,

When IIS is unable to handle the problem, the above error occurs. An error occurs when the user traffic of an application exceeds the limit. Improve your program, use the cache, and minimize the number of interactions with the database.

 

 

VI,

The problem I encountered was that I had no intention to reset the DataSet reference, and this problem occurred later. Please check your code and check whether it was re-referenced elsewhere, in my program, DataSet is set as a global object.

 

 

VII,

When you find that all methods are not running, install the. netframework patch.

 

 

8,

This error occurs only because the DAL dll file in the website is invalid. The business layer cannot instantiate the objects in IDAL, but it also wastes an afternoon in code calling.

 

 

IX,

Add monitoring for every suspicious location. At first, I thought it was an SQL statement error. I checked it several times and returned the same error when I used the SQL statement. According to the results from google, when we mention object redefinition, this will happen. According to this prompt, the page-level global object is replaced. Class DBOper {/* constructor does not have the function body ** c # Write a series of database operation methods **} initially to save time and minimize object declaration, only one private DBOper db = new DBOper () is declared globally, and the method of this object is called in different methods to avoid Memory waste caused by definition. After code reconstruction, no error was reported during compilation. However, when running, "NullReferenceException: the object reference is not set to the instance of the object" appears. As a result, it took several hours. Later, according to google's results, the DBOper objects used in different methods were redefined as local variables one by one (only one DBOper object was defined in a method, and the method was normally called multiple times ), remove the global private variable. It will be normal again. Why does this problem occur when the custom object is promoted to class as private and used in different methods, it is not clear now .........................

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.