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

Topics: Data Access Application Block, Enterprise Library Core
Jun 21, 2013 at 12:51 AM
I have two websites both of which are based off the same code base. however one website had some additional work done to it which included adding the MS enterprise lib to it.

I'm in the process of updating the code on the other site so that both sites will be running the same code again.

however, I'm getting the error "The type Database cannot be constructed. You must configure the container to supply this value" when i try to run a page which is using the ent lib.
private static Database dbConn = DatabaseFactory.CreateDatabase("default");
That's the line of code that is failing.

<connectionStrings>
<add name="default" connectionString="Server=localhost;Database=XYZ;User ID=user123;Password=pwd456;"/>
</connectionStrings>

I do have a connection string set up in the web.config. I have a using Microsoft.Practices.EnterpriseLibrary.Data; in the page. I've got the ent lib dlls in my websites bin folder.

This code works fine on the other site. I'm guessing I'm missing something in the web.config or some other setup/configuration step - just not sure what.
Anyone have any ideas how to resolve this?
Jun 21, 2013 at 12:58 AM
Of course the quickest way to find the solution to a problem is to post a question, at which point you'll find the answer 1-2 minutes after posting the question :)

For anyone else, the connection string needs to specify the providerName, providerName="System.Data.SqlClient"