Enterprice Library 5 and WCF 4.0 DAAB

Topics: Data Access Application Block
Oct 11, 2010 at 5:53 PM


i´m still learning about the enterprise library 5. the environment is a mssql server 2008r2 with the adventureWorks2008R2 sample db and vs2010.

my "first" exercise is to use the daab. i´m use the "Microsoft Enterprise Library 5.0 - Hands On Labs" and the works fine.

my next step is, to combine this with a simple wcf service like this:

namespace ProductsServiceLibrary

// Dienstvertrag, der die vom WCF-Dienst bereitgestellten Operationen beschreibt
public interface IProductsService
// Produktnummern für alle Produkte abrufen
List<string> ListProducts();

// WCF-Dienstklasse, die den Dienstvertrag implementiert
public class ProductsService : IProductsService
private Database _db;

public List<string> ListProducts()
// Konfigurationsdaten für die Verbindung zur Konfigurationsdaten für die Verbindung zur AdventureWorks-Datenbank lesen
_db = EnterpriseLibraryContainer.Current.GetInstance<Database>("AdventureWorksConnection");

// Liste der Produkte erstellen und füllen
List<string> productsList = new List<string>();

// Abrufen der Details zu allen Produkten mit einem DataReader
string queryString = @"SELECT ProductNumber FROM Production.Product";
using (IDataReader productsReader = _db.ExecuteReader(CommandType.Text, queryString))
while (productsReader.Read())
string productNumber = productsReader.GetString(0);

//Liste der Produkte zurückgeben
return productsList;


here the app.config
<?xml version="1.0" encoding="utf-8" ?>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <dataConfiguration defaultDatabase="AdventureWorksConnection" />
        <add name="AdventureWorksConnection" connectionString="Database=AdventureWorks2008R2;Server=(local)\SQLEXPRESS;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />

produce this error message:

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

Server stack trace:
   bei System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   bei IProductsService.ListProducts()
   bei ProductsServiceClient.ListProducts()

a simplified console application without wcf works fine...

thanks for comment
Oct 12, 2010 at 12:09 AM

Your AdventureWorksConnection connection string should be defined in your web.config of the wcf project, not on the console application's.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.