ActivationException ASP.NET MVC

Topics: Data Access Application Block
Mar 11, 2013 at 9:05 PM
Edited Mar 11, 2013 at 9:13 PM
I have a simple ASP.NET solution set up with three projects:
  1. A base library of a couple objects I set up.
  2. A Web API project
  3. An MVC 4 project
Projects 2 and 3 have a config file with the following code:

<add name="DefaultConnection" connectionString="Server=WORK-PC;Database=DevUT;Integrated Security=SSPI" />

I have tried setting Trusted_Connection to true as well.

The code in my Web API project is as follows:
Database db = DatabaseFactory.CreateDatabase("DefaultConnection"); //fails here even with CreateDatabase()
IDataReader dr = db.ExecuteReader(CommandType.Text, "SELECT * FROM Package");

I keep getting an error saying Activation error occured while trying to get instance of type Database, key "".

Additionally, I get prompted for the ServiceLocatorImplBase.cs file the first time I run the solution after opening Visual Studios.

My version of Unity is 2.1.505.2 and my version of Enterprise Library is 5.0.505.0.
Unity was preinstalled and Enterprise Library was installed with NuGet.

I have SQL Server 2012 (I don't think it's express) set up on the same machine that the project is running. I have a server (WORK-PC) running with a database (DevUT) underneath.

Any ideas? I can't seem to figure out how to connect to the database :/.
Mar 11, 2013 at 11:37 PM
Edited May 1, 2013 at 9:38 PM
The message is indicating that the connection named "DefaultConnection" could not be found.

The reason is probably that the provider is not specified. Try:
<add name="DefaultConnection" 
         connectionString="Server=WORK-PC;Database=DevUT;Integrated Security=SSPI" 
         providerName="System.Data.SqlClient" />
Randy Levy
Enterprise Library support engineer
Support How-to
Mar 12, 2013 at 12:58 AM
That fixed it randylevy! Thank you so much! I've been working on this on and off for 7 hours.