The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

delete picture delete · Mar 27, 2011 · Viewed 45.4k times · Source

I have two projects in a solution.

  1. PizzaSoftware.Data
  2. PizzaSoftware.UI

In the Data project, I have my Entity Framework model which connects to my database.

My UI project has a project reference to Data and here's how it looks like:

enter image description here

I've created a user control in the UserControls folder.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PizzaSoftware.Data;

namespace PizzaSoftware.UI.UserControls
{
    public partial class AutoCompleteTextBox : UserControl
    {
        AutoCompleteStringCollection completeCollection = new AutoCompleteStringCollection();

        public AutoCompleteTextBox()
        {
            InitializeComponent();
        }

        private void AutoCompleteTextBox_Load(object sender, EventArgs e)
        {
            CustomerRepository repo = new CustomerRepository();
            var customers = repo.FindAllCustomers().ToList();

            foreach (var customer in customers)
            {
                completeCollection.Add(customer.Name);
            }

            txtSearchBox.AutoCompleteMode = AutoCompleteMode.Suggest;
            txtSearchBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtSearchBox.AutoCompleteCustomSource = completeCollection;
        }
    }
}

When I try to drag this user control into the design pane, I receive the error in the question title.

Here's what my connection string looks like:

<connectionStrings>
   <add 
      name="SaharaPizzaEntities"
      connectionString="
         metadata=res://*/PizzaSoftwareEntityModel.csdl|res://*/PizzaSoftwareEntityModel.ssdl|res://*/PizzaSoftwareEntityModel.msl;
         provider=System.Data.SqlClient;
         provider connection string=&quot;
            Data Source=.\SQLEXPRESS;
            Initial Catalog=SaharaPizza;
            Integrated Security=True;
            MultipleActiveResultSets=True
         &quot;"
      providerName="System.Data.EntityClient"
/>

What could be causing this error?

Answer

Albert Tolokonnikov picture Albert Tolokonnikov · May 21, 2012

Copy <connectionStrings> from App.Config from PizzaSoftware.Data to web.config from PizzaSoftware.UI and add to web.config

<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>