在配置中找不到指定的命名连接,不适合与 EntityClient 提供程序一起使用,或者无效
我的解决方案中有两个项目。
- PizzaSoftware.Data
- PizzaSoftware.UI
在数据项目中,我有连接到数据库的实体框架模型。
我的 UI 项目有一个对数据的项目引用,如下所示:
我已创建一个用户控件位于 UserControls 文件夹中。
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;
}
}
}
当我尝试将此用户控件拖到设计窗格中时,我在问题标题中收到错误。
我的连接字符串如下所示:
<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"
/>
是什么导致了此错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
将
从 App.Config 从 PizzaSoftware.Data 复制到 web.configPizzaSoftware.UI 并添加到 web.config
Copy
<connectionStrings>
from App.Config from PizzaSoftware.Data to web.config fromPizzaSoftware.UI and add to web.config
在你的 app.config 中,你的连接字符串看起来像……
注意 "。尝试将其更改为单引号 '
In your app.config, your connection string look like..
Notice the ". Try changing that to a single quote '
我刚刚发现,如果从 VS2010 的 IIS 中创建应用程序的虚拟目录,距网站根目录两层,就会发生此错误。不确定为什么会发生,需要进行更多调查。
例如,如果您的应用程序位于以下路径:
/admin/advertiser
,并且您的 IIS 站点中没有/admin
虚拟目录,则会出现错误。我所做的就是在我的
.../intepub/wwwroot
中创建一个空的admin
目录,然后错误消失了。您会发现,在执行上述步骤之前,您将无法开始调试。
我们的团队过去曾遇到过这个问题,需要一些时间才能记住,但这正是我们之前解决它的方法。
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.
连接字符串看起来像是 EntityClient 提供程序的有效字符串,因此我的猜测是来自“在配置中找不到指定的命名连接”的异常消息。
配置中连接字符串的名称是“SaharaPizzaEntities”。当您创建派生对象上下文时,您是否明确指定了“命名连接”?
生成的对象上下文类有多个构造函数,其中一个是无参数的:
name=EntityModelContainer
是连接字符串名称,必须与配置文件中的连接字符串(“SaharaPizzaEntities”)匹配。您可以更改配置文件中的名称或使用第二个构造函数,它允许显式定义连接字符串名称: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:
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:我遇到了同样的问题,所以我像你一样使用 2 个线程,我认为这是因为库中没有运行,然后我将它放入主项目中,然后开始它成功完成工作。
这可能是一种解决方案,不是您需要的,但您可以解决这个问题,
请原谅我的英语。
我希望这可以帮助你
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
这个问题很容易解决。只需将您的连接字符串从
Aap.Config
复制到Web.config
文件,这肯定会运行您的应用程序。这对我来说很有效。当您在另一个项目中拥有数据类/实体并且在单独的项目中拥有网页时,会发生此错误。
The problem can easily be solved. Just copy your connection string from
Aap.Config
toWeb.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.
我在项目中也遇到了同样的问题。
我有 3 个不同的项目
我刚刚在 View 的应用程序配置中复制了连接字符串,它工作正常。
问题的原因是“”“连接字符串在本地不可用,而需要它””“。
I was also facing the same problem in my project.
I was having 3 different projects
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""".
这是一个不起作用的示例连接字符串
我给出连接字符串的错误是
问题是路径
请参阅连接字符串中使用的 *
将 * 替换为放置 edmx 文件的命名空间
将命名空间而不是 * 放置在您的 appconfig 文件中
我的 edmx 文件的命名空间是 IemrWebs.Data。模型
所以我用 IemrWebs.Data.Model 替换了 * 见下文,它正在工作
下面是正确的连接字符串
Here is a sample connection string which was not working
my error giving connection string was
Problem is with path
see the * used in the connection string
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
我遇到了同样的问题&我尝试了所有提到的方法。最后我按照提到的解决了它。就我而言,我有单独的数据层和表示层。在我的 app.config (数据层)中,我有这样的连接。
在我的 web.config 中,我手动配置了连接,如下所示:
它给了我与上面提到的相同的异常。所以我通过在 Web 配置文件中添加 app.config 值来解决它。
我的最终 web.config 文件如下:
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.
in my
web.config
i manually configured connection as follows: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:我认为你的配置文件不在Web项目中,它在其他一些DLL中......不太确定......但你的连接字符串应该在正在执行的项目的web.config中......
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...