问题
I have two projects in a solution.
- PizzaSoftware.Data
- 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:

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="
Data Source=.\SQLEXPRESS;
Initial Catalog=SaharaPizza;
Integrated Security=True;
MultipleActiveResultSets=True
""
providerName="System.Data.EntityClient"
/>
What could be causing this error?
回答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 ". Try changing that to a single quote '
回答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>
回答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.
回答4:
The connection string looks like a valid string for the EntityClient provider, so my guess would be from the exception message that "the specified named connection is not found in the configuration".
The name of the connection string in the configuration is "SaharaPizzaEntities". Did you specify the "named connection" explicitely when you create your derived object context?
The generated object context class has several constructors, one is parameterless:
public EntityModelContainer() : base("name=EntityModelContainer",
"EntityModelContainer")
name=EntityModelContainer
is the connection string name which must match to the connection string in your configuration file ("SaharaPizzaEntities"). You could either change the name in the config file or use the second constructor which allows to define the connection string name explicitely:
public EntityModelContainer(string connectionString) : base(connectionString,
"EntityModelContainer")
回答5:
I had the same problem, so I was using the 2 thread like you and I thought that was because in the library doesn't run, then I put it in the principal project and then begin it to work completed successfully. This could be one solution, not what you need but you could resolve with this
please excuse my english.
I hope this can help you
回答6:
The problem can easily be solved. Just copy your connection string from Aap.Config
to Web.config
file, this will surely run your apps. This works properly for me.
The error occurs when you have dataclass/entity in another Project and WebPages in a separate project.
回答7:
I was also facing the same problem in my project. I was having 3 different projects
- Data in which I added the entity framework. this project was having the App.config file with the connection string
- Presenter: with my Presenter
- View: with UI.
I just copied the Connection string in the app config of View and it works fine.
and the reason of the problem was """Connection string not available locally, where it was required""".
回答8:
Here is a sample connection string which was not working
my error giving connection string was
<connectionStrings>
<add name="IEMRWEBSEntities" connectionString="metadata=res://*/IemrWebs.csdl|res://*/IemrWebs.ssdl|res://*/IemrWebs.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.25;initial catalog=IEMRWEBSSitecore_Custom;persist security info=True;user id=IEMRWEBS;password=aDn16s!$AaS;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
Problem is with path
see the * used in the connection string
"metadata=res://*/IemrWebs.csdl|res://*/IemrWebs.ssdl|res://*
replace * with the namespace in which your edmx file is placed
place the namespace instead of * in your appconfig file
my namespace of edmx file is IemrWebs.Data.Model so i have replaced * with IemrWebs.Data.Model see below and it is working Below is the correct connection string
<connectionStrings>
<add name="IEMRWEBSEntities" connectionString="metadata=res://IemrWebs.Data.Model/IemrWebs.csdl|res://IemrWebs.Data.Model/IemrWebs.ssdl|res://IemrWebs.Data.Model/IemrWebs.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.25;initial catalog=IEMRWEBSSitecore_Custom;persist security info=True;user id=IEMRWEBS;password=aDn16s!$AaS;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
回答9:
I got same problem & i tried all the mentioned method. finally i solved it as mentioned. In my case I have separate data layer and presentation layer. in my app.config (data layer) I have connection like this.
<add name="LibraryMgtSysEntities" connectionString="metadata=res://*/DataLibraryMgtSys.csdl|res://*/DataLibraryMgtSys.ssdl|res://*/DataLibraryMgtSys.msl;provider=System.Data.SqlClient;provider connection string="data source=abc;initial catalog=LibraryMgtSys;Persist Security Info=True;user id=sa;password=123;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
in my web.config
i manually configured connection as follows:
<add name="DefaultConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=abc;
Initial Catalog=LibraryMgtSys;
Integrated Security=SSPI;
user id=sa;password=123;" />
it gives me same exception as mentioned above. so i solved it by adding app.config value in web config file.
my final web.config
file as follows:
<connectionStrings>
<clear />
<add name="LibraryMgtSysEntities" connectionString="metadata=res://*/DataLibraryMgtSys.csdl|res://*/DataLibraryMgtSys.ssdl|res://*/DataLibraryMgtSys.msl;provider=System.Data.SqlClient;provider connection string="data source=TILANITHOTAMUNE\SQLEXPRESS;initial catalog=LibraryMgtSys;Persist Security Info=True;user id=sa;password=testing;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
<add name="DefaultConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=abc;
Initial Catalog=LibraryMgtSys;
Integrated Security=SSPI;
user id=sa;password=123;" />
</connectionStrings>
回答10:
I think your config file is not in the web project, it is in some other DLL....not so sure...but your connection string should be in the web.config of project being executed...
来源:https://stackoverflow.com/questions/5450931/the-specified-named-connection-is-either-not-found-in-the-configuration-not-int