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

Source: Internet
Author: User
Tags microsoft website

You have not set the object reference to the instance of the object. The following are various analyses and solutions to possible problems.

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. Why can't I find the problem? In this case, the. NET FRAMEEWORK framework installed on your local machine may be faulty. The SP1.1 patch may not be installed.
Install NET FRAMEEWORK1.1 SP1 on the official Microsoft website.

IV,

I personally summarize the following situations where NullReferenceException occurs:
1. The namespace of the object is not referenced.
2. The object is not instantiated.
3. If 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 and the business layer cannot instantiate the objects in IDAL.
But it also wasted one afternoon on 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 {
/* The constructor does not have a function body.
*
* C # Write a series of Database Operations
*
*
}
Initially, to save time and minimize object Declaration, only a private DBOper db = new DBOper () is declared globally, and the method of the 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.