c# - 在配置中找不到指定的命名连接,不打算与 EntityClient 提供程序一起使用,或者无效

标签 c# visual-studio-2010 entity-framework windows-forms-designer

我在一个解决方案中有两个项目。

  1. PizzaSoftware.Data
  2. PizzaSoftware.UI

在数据项目中,我有连接到我的数据库的 Entity Framework 模型。

我的 UI 项目有一个对数据的项目引用,它是这样的:

enter image description here

我在 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;
        }
    }
}

当我尝试将此用户控件拖到设计 Pane 中时,我收到问题标题中的错误。

这是我的连接字符串的样子:

<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"
/>

什么可能导致此错误?

最佳答案

复制<connectionStrings>从 App.Config 从 PizzaSoftware.Data 到 web.config 从 PizzaSoftware.UI 并添加到 web.config

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

关于c# - 在配置中找不到指定的命名连接,不打算与 EntityClient 提供程序一起使用,或者无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5450931/

相关文章:

c# - Nopcommerce 更新实体问题

c# - Sitecore:使用 LINQ 与 ID 进行比较的有效方法

VB.NET 项目文件夹问题

visual-studio-2010 - 是否可以导出 TFS 2010 构建定义?

asp.net-mvc - EF 不会检测到更改

c# - MVC 4 编辑 Controller /查看多对多关系和复选框

c# - 在 .NET 4.5 + 中使用 HttpClient 执行 XML 请求

c# - 如何调试 Azure 中 ASP.NET Web 应用程序的 502 错误?

c# - 将动态控件插入控件集合的中间

html - 需要 CSS 帮助