tags:

views:

362

answers:

1

Hi There,

I'm using CSLA 3.6

I keep getting the error:

DataPortal.Fetch failed (Database name not found in config file (AdventureWorksLT))

My Dataportal_Fetch code looks like this :

Private Overloads Sub DataPortal_Fetch(ByVal criteria As SingleCriteria(Of Customer, Integer))
    Using ctx = ContextManager(Of DalLinq.AdventureWorksDataContext).GetManager(DalLinq.Database.AdventureWorksLTConnectionString)
        Dim data = (From p In ctx.DataContext.Customers Where p.CustomerID = criteria.Value Select p).Single
        LoadProperty(Of Integer)(CustomerIdProperty, data.CustomerID)
        LoadProperty(Of String)(CompanyNameProperty, data.CompanyName)
    End Using
End Sub

My Database.vb file looks like this:

Public Class Database

Public Const AdventureWorksLTConnectionString As String = "AdventureWorksLT"

End Class

And my App.Config file contains the following(Substitutes < and > character with ( and ) due to stackoverflow :

(connectionStrings) (add name="AdventureWorksLT" connectionString="Data Source=(local);Initial Catalog=AdventureWorksLT;User Id=AdvWorks;Password=UserPW;" providerName="System.Data.SqlClient" /) (/connectionStrings)

What am I missing?

Thanks!

A: 

Make sure that you are using the correct app.config file. The ConfigurationManager looks at the current running project (i.e. your test project and/or your windows forms/console app).

The default behavior for the ContextManager is to use ConfigurationManager to look for the named connection string unless you pass true to the second parameter in the ContextManager, then it will just use the provided string as the connection string.

Jamie Wright