Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Microsoft.Practices.ServiceLocation.ActivationException–EnterpriseLibrary The type Database cannot be constructed

with 16 comments

While moving code first time to live server, we started to get following error. I found that the issue in my case is, I do not put providerName="System.Data.SqlClient"  in following connection string.

    <add name="XYZ" connectionString="Data Source=localhost;Initial Catalog=LondonDreams;Persist Security Info=True;User ID=dream;Password=dream" providerName="System.Data.SqlClient"/>

Once I put that in above part, it worked fine for below error.

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "XYZ"
—> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of
—> the dependency failed, type =
"Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "XYZ".
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,XYZ
—> System.InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.

Smile

Written by Manish

November 12, 2010 at 10:49 am

16 Responses

Subscribe to comments with RSS.

  1. Wow, I spent hours on this crap. That missing provider name was the culprit. Ugh. Thanks!

    Dennis

    May 13, 2011 at 11:21 am

    • Thanks a lot for your post. It is really a great one. I never miss this provider name again.

      Sukamal Sengupta

      February 19, 2013 at 12:52 pm

  2. thanks, I spent days. lol

    bolaji musiliudn

    May 20, 2011 at 11:59 pm

  3. I will gonna kill this provider name..Thanks a ton my problem also got resolved

    ankit

    June 1, 2011 at 6:16 am

  4. thanks man. This is a real help. I’ve been debugging my code for several days when I found this blog.

    adihapz

    June 12, 2011 at 12:53 pm

  5. I have same issue here, yet I do have the providername specified 😦

    Olivier

    June 20, 2011 at 12:54 am

    • could you paste it here. And do you know if provider is installed or not?

      Manish

      June 20, 2011 at 1:54 am

  6. i am trying to connect to mysql and i have put the required dlls from devart project in order to have a dotConnect to mysql.
    My web.config goes as follows :

    <!– –>



    <!–
    –>


    <!–
    –>

    When i execute and change the connection string to the SQL Server one, my app is brought out correctly. When i use the MySQL one, i get the following error :

    [InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.]
    Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +161
    Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +136
    Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
    Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +108
    Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +137
    Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +190
    Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +163

    [ResolutionFailedException: Resolution of the dependency failed, type = “Microsoft.Practices.EnterpriseLibrary.Data.Database”, name = “CloudMobDSN”.
    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,CloudMobDSN

    ANY SUGGESTIONS ?? PLEASE ???

    iunabillyrid

    December 28, 2011 at 2:31 am

  7. my web.config goes as follows :

    <!– –>

    iunabillyrid

    December 28, 2011 at 2:50 am

  8. //
    //<!– –>
    //
    //

    iunabillyrid

    December 28, 2011 at 2:52 am

  9. Thank you! Just spent hours on this. I wish the error message were a little more specific…

    Tom

    February 6, 2012 at 6:17 pm

  10. Saved me a lot of time, thanks.

    • Thanks manish…U saved me

      kiran

      April 3, 2013 at 10:14 pm

  11. Works for me also. tag providerName=”System.Data.SqlClient” is missing from my connection string also.

    Shoaib

    January 25, 2013 at 6:12 pm

  12. Thanks to this blog.

    Neil

    March 23, 2018 at 12:13 am


Leave a comment