An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an objectobject reference not set to an instance of an object" (NullReferenceException) means that you are referring to an object the does not exist or was deleted or cleaned up. In order to prevent the error, objects that could be null should be tested for null before being used.
if (mClass != null)
{
// Go ahead and use mClass
mClass.property = ...
}
else
{
// Attempting to use mClass here will result in NullReferenceException
}
A NullReferenceException typically reflects developer error and is thrown in the following scenarios:
Forgotten to instantiate a reference type.
Forgotten to dimension an array before initializing it.
Is thrown by a method that is passed null.
Get a null return value from a method, then call a method on the returned type.
Using an expression to retrieve a value and, although checking whether the value is null.
Enumerating the elements of an array that contains reference types, and attempt to process one of the elements.
MySqlConnection open object reference not set to an instance of an object
- rahul kumar
- Posts: 1
- Joined: Mon Feb 01, 2021 6:49 am
MySqlConnection open object reference not set to an instance of an object
Hello Rahul,
I saw you reply from earlier this year while I had about the same problem again and rechecked what I wrote here and others replied. I finally found that the "object reference not set..." error was the (hardly logical) result from the connection string. After some trial & error I managed to get a proper exception description logged and it said Access Denied. This didn't make sense in 2 ways: the connection string was working perfectly with WCF (probably explained because that concept works differently) and also because I do not expect this error; there were no null objects, which I tested following your mail.
With a different connection string (read: user + password to the same MySQL database) the Open worked this time and the rest of the code, returning the result of a query called from VO and executed from the X# DLL, also worked.
Dick
I saw you reply from earlier this year while I had about the same problem again and rechecked what I wrote here and others replied. I finally found that the "object reference not set..." error was the (hardly logical) result from the connection string. After some trial & error I managed to get a proper exception description logged and it said Access Denied. This didn't make sense in 2 ways: the connection string was working perfectly with WCF (probably explained because that concept works differently) and also because I do not expect this error; there were no null objects, which I tested following your mail.
With a different connection string (read: user + password to the same MySQL database) the Open worked this time and the rest of the code, returning the result of a query called from VO and executed from the X# DLL, also worked.
Dick