Activation error occured while trying to get instance of type Database, key ""

Topics: Data Access Application Block
May 16, 2013 at 1:15 PM
Hi All,

I am working on creating a new windows application -Client. I am encountering a problem when I attempt to use the Data Access Block .When i try to run i get the error "{"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)

The App.config file contains
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
    <add name="STAGE"
                    connectionString="Password=Hi1241!;Persist Security Info=True;User ID=Server;Initial Catalog=Mercury;Data Source=Florida"/>
<dataConfiguration defaultDatabase="STAGE" />
Please help.

I could get the error in the Create Database code below:
Private Function GetDatabase(ByVal dbKey As String) As Database
    Dim db As Database = Nothing

    If dbKey = "" Then
        db = DatabaseFactory.CreateDatabase()

        db = DatabaseFactory.CreateDatabase(dbKey)
    End If

    Return db

End Function
May 16, 2013 at 3:49 PM
Everything looks fine. Are you sure that the app.config is deployed along with the .exe (e.g. as myapp.exe.config)? Otherwise, if you could supply a sample project it would help determine what the issue is.

Randy Levy
Enterprise Library support engineer
Support How-to