I have a client application consuming a WCF service throws an Error

> 
> Object reference not set to an instance of an object.
> 
> 
> 

Details:

I am using WCF service with Microsoft Enterprise library for database connectivity, the service runs fine in the self hosted environment but throws an error if hosted as a `windows service`. I am not able to debug the WCF service, since it is hosted as windows service, so i tried using try catch blocks to find out, where the problem is.

I came across these two lines which i found to be most suspicious

```
Database db = DatabaseFactory.CreateDatabase();
DbConnection conn = db.CreateConnection();

```

I have already set my default database in config file. i think the second line must be the cause.

Please help.

Tried to find similar question on stack overflow but failed, hence posted.

> 
> Appended Question statement with error snap + stack trace...
> 
> 
> 

![enter image description here](https://i.stack.imgur.com/tdvqp.png)

**stack trace**

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get\_DefaultName()

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault()

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase()

at WCFService.Service1.ExecuteSFDS(Cmd CmdObj, Int32 executionType) in D:\Projects\WCFService\WCFService\Service1.cs:line 32