【问题标题】:FIrst EntityDataSource Works, Second Says Connection For First is Empty or Invalid第一个 EntityDataSource 工作,第二个说第一个连接是空的或无效的
【发布时间】:2016-03-12 11:51:56
【问题描述】:

我从事 .NET 多年,但实体模型正在吃我的午餐。

在我们编写新课程时,我一直在为我的学校改编 70-515 Training Kit 中的练习,以便在 Visual Studio 2013 上使用。我一直无法在Training Kit to work in Visual Studio 2013 的页面716-718 上进行练习。

我已经能够通过将我的应用程序池更改为使用 32 位应用程序来克服程序集加载问题,并且已经弄清楚如何安装 EF 以便可以创建源。这有一些问题(例如,EF 没有创建命名空间)但实体模型正在被接受。

我无法克服的一个错误是网站运行时程序出错:

指定的命名连接在 配置,不打算与 EntityClient 提供程序一起使用, 或无效。

我在Windows 8.1 上使用Visual Studio 2013 Express。这里有版本问题吗?

这里奇怪的是页面上有两个EntityDataSources - 第一个有效。两者都使用相同的连接(我安装了LocalDB)。我得出的结论是,这需要帮助。有没有人知道如何让它工作?

如果问题太长,你能告诉我Dallas-Fort Worth 区域内某人的名字吗?

注意:此站点不喜欢 XML。我会邮寄任何回复我的人 web.config 和实体模型的 XML 作为附件。

我的页面上的标记如下:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.</p>
    <p><a href="http://www.asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
    <div class="col-md-4">
        <h2>Customers</h2>
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=NorthwindEntitiesCnn" 
            DefaultContainerName="NorthwindEntitiesCnn" EnableFlattening="False" AutoPage="true" AutoSort="true"
            OrderBy="it.CompanyName" EntitySetName="Customers" 
            Select="it.[CompanyName], it.[CustomerID], it.[City], it.[Region], it.[Country], it.[Phone]">
        </asp:EntityDataSource>
        <asp:GridView ID="GridViewCustomers" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
            DataSourceID="EntityDataSource1">
            <Columns>
                <asp:BoundField DataField="CustomerID" HeaderText="ID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="Company" ReadOnly="True" SortExpression="CompanyName" />
                <asp:BoundField DataField="City" HeaderText="City" ReadOnly="True" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" ReadOnly="True" SortExpression="Region" />
                <asp:BoundField DataField="Country" HeaderText="Country" ReadOnly="True" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" ReadOnly="True" SortExpression="Phone" />
                <asp:HyperLinkField DataNavigateUrlFields="CustomerID" DataNavigateUrlFormatString="orders.aspx?custId={0}"
                    HeaderText="Orders" Text="view orders" />
            </Columns>
        </asp:GridView>
        <asp:EntityDataSource ID="EntityDataSourceCust" runat="server" ConnectionString="name=NorthwindEntitiesCnn" DefaultContainerName="NorthwindEntitiesCnn" EnableFlattening="False" EntitySetName="Customers" Where="it.CustomerID=@custId" Include="Orders">
          <WhereParameters>
              <asp:QueryStringParameter QueryStringField="custId" Name="custId" DbType="String"/>
          </WhereParameters>
        </asp:EntityDataSource>
        <asp:DetailsView ID="DetailsViewCust" DataSourceID="EntityDataSourceCust" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="CustomerID" OnDataBound="DetailsViewCust_DataBound">
            <Fields>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
            </Fields>
        </asp:DetailsView>
        <asp:GridView ID="GridViewOrders" runat="server"></asp:GridView>
    </div>
</div>

页面的代码如下:

public partial class _Default : Page
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }

  protected void DetailsViewCust_DataBound(object sender, EventArgs e)
  {
    Customer cust =
    (Customer)DetailsViewCust.DataItem;
    this.GridViewOrders.DataSource = cust.Orders;
    this.GridViewOrders.DataBind();
  }
}

【问题讨论】:

  • 您能分享您的 web.config 或 app.config 中的连接字符串吗?他们有可能出现问题,

标签: .net entity-framework connection-string


【解决方案1】:

我觉得自己好笨!很抱歉浪费了您的时间;在分析我遇到的所有奇怪错误时,在解决它们后,我忽略了两个实体数据源必须在不同的页面上!很抱歉浪费了你的带宽……如果没有别的,把我的问题留给你至少让我可以整理我的想法。

                                                        Clark.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-15
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    相关资源
    最近更新 更多