Search code examples
c#databasepostgresqlweb-configenterprise-library

Microsoft.Practices.EnterpriseLibrary.Data CreateDatabase error


my company got a project from another company which has closed. All we need now is change connection strings to our DB, which is full similar as prodaction DB. I changed the server address to ours, the database name and password remained the same. I compile and run, an error occurs when creating / connecting to the database.

public void InitDatabase(string dbName)
{
   _databaseObject = dbName == null
        ? MEL.DatabaseFactory.CreateDatabase()
        : MEL.DatabaseFactory.CreateDatabase(dbConnectionString);
}

If an empty string comes to the input, then it connects to the database by default, otherwise to the specified database.

When I start it, a error throw there.

Microsoft.Practices.ServiceLocation.ActivationException: "Activation error occured while trying to get instance of type Database, key """

Inner exception #1:

ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value. At the time of the exception, the container was: Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)

Inner exception #2:

InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.

It says "You must configure the container". But noone know how to do it.

All the solutions that I found did not help, or were very old, about 2007-2012. 3 developers have already dealt with this problem before me, but no one has managed to solve this problem. The code is definitely working, because a similar build of the program works on the server. The difference is only in the settings file, which differ only in the addresses of the servers with the database. I can't upload the configuration file because of the NDA, but if some part of it is needed, I can show an approximate view of the file.


Solution

  • Reinstalled Npgsql with all additional parameters.