Asp.net running prompt does not set object reference to object instance error Solution

Source: Internet
Author: User

The instance where the object reference is not set to the object
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 the instance where the object reference is not set to 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. NETFRAMEEWORK framework installed on your local machine may be faulty, and the SP1.1 patch may not be installed.
NET needs to be reprinted from the percentage of network http://www.oh100.com, please keep this flag FRAMEEWORK1.1SP1 patch, to the Microsoft official website to download and install just fine.
4. If NullReferenceException occurs, I personally summarize the following situations:
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.
5. The above error may also occur when IIS is unable to handle it.
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.
6. The problem I encountered was that I had no intention to reset the DataSet reference. Then, I encountered this problem. Please check your code to see if it was re-referenced elsewhere, in my program, DataSet is set as a global object.
7. When you find that all methods are not running, install the. netframework patch.
8. I encountered this error. Because the DAL dll file in the website is invalid, 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.
ClassDBOper {
/* The constructor does not have a function body.
** C # A series of Database Operations
**} At first, we declared as few objects as possible to save trouble. We only declared a global privateDBOperdb = newDBOper () and called the method of this object in different methods, to avoid Memory waste caused by definition. After code reconstruction, no error was reported during compilation. However, when running, "NullReferenceException: 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.
It is not clear why this problem occurs when the User-Defined Object is promoted to class as private and used in different methods.
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.