Tuesday, June 10, 2008

Repository Factory Error: Object reference not set to an instance of an object.

Problem Statement
If you are using repository factory to create your data access layer and you get error in page showing

"Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object."

And the problem is pointing you at the Repository Object, for example:

Line xx: public sampleRepository()
Line xx: : base()

The problem comes from the connection string. You have not specified a default connection that you are using.

Solution
1.) Open your web.config with your Enterprise Library Editor, and select Data Access Application Block node and open it in Propertise.
2.) In the DefaultDatabase field, select your connection string that you have created.

Compile the project and run again. It should work now.

No comments: