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

45,715

Solution 1

In your app.config, your connection string look like..

   connection string="
      Data Source=.\SQLEXPRESS;
      Initial Catalog=SaharaPizza;
      Integrated Security=True;
      MultipleActiveResultSets=True
   "

Notice the &quot. Try changing that to a single quote '

Solution 2

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>

Solution 3

I just found that if virtual directory for an app is created in IIS from VS2010 two levels from the website root this error would occur. Not sure why it happens, would need to investigate more. For example, if your app is in this path: /admin/advertiser the error would appear if you don't have /admin virtual directory in your IIS site.

All I did is created an empty admin directory in my .../intepub/wwwroot and error disappeared.

You will find that you won't be able to start debugging until you do the step above.

We had this problem in our team in past, it took some time to remember but this was exactly how we fixed it before also.

Share:
45,715
Admin
Author by

Admin

Updated on April 23, 2020

Comments

  • Admin
    Admin about 4 years

    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?

  • Tom Stickel
    Tom Stickel over 12 years
    I have same error message in a project, and changing that did not help. It is a testing/side project so if I have a solution I will be sure to leave a comment to help someone else.
  • Tom Stickel
    Tom Stickel over 12 years
    Ok, I just fixed my project. It always compiled fine, the problem with mine was from a unit test project which needed me to add the same connection string to the App.Config file in the unit test project. All is fixed for me. I still have &quot; and that works fine for me, but I have seen msdn site where that single quote (') fixed it for them. Either way.... not a "fun" error as it is too vague. Oh well
  • Admin
    Admin about 11 years
    Albert Tolokonnikov's Solution worked for me, I Copied the connection strings in the web.config of my entity framework project to the web.config of my running project.
  • Jarrette
    Jarrette about 11 years
    like tom said, I added the same connection string from my app.config to my web.config.
  • user441058
    user441058 about 8 years
    I just happened to have a VS 2010 project open to look at some source code when this happened. Closing it made the error with VS 2015 go away. That's messed up.