Object reference not set to an instance of an object error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a program that uses the OleDbConnection class using C++.NET. I have
all of the appropriate includes, namespaces, references, etc. and declare the
class:

class OleDBClass {
public:
gcroot<OleDbConnection*> oleConn;
OleDBClass( ) {}
};

inside my application class. It builds just fine with that. Now I want to
open a new OleDbConnection with the following in my application class
InitInstance method:

OleDBClass *oleDBCONN;
oleDBCONN->oleConn->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<some database name>;User
Id=admin;Password=";
oleDBCONN->oleConn->Open();

When I run it I get the error "Object reference not set to an instance of an
object", on the oleDBCONN->oleConn->ConnectionString call.

Any help would be greatly appreciated.

Thanks
 
I have a program that uses the OleDbConnection class using C++.NET. I have
all of the appropriate includes, namespaces, references, etc. and declare
the
class:

class OleDBClass {
public:
gcroot<OleDbConnection*> oleConn;
OleDBClass( ) {}
};

inside my application class. It builds just fine with that. Now I want to
open a new OleDbConnection with the following in my application class
InitInstance method:

OleDBClass *oleDBCONN;
oleDBCONN->oleConn->ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<some database name>;User
Id=admin;Password=";
oleDBCONN->oleConn->Open();

You're declaring the variable for the connection, but never actually
initializing it... At the least, do:

class OleDBClass {
public:
gcroot<OleDbConnection*> oleConn;
OleDBClass( ) { oleConn = new OleDbConnection(); }
};
 
Back
Top