-1

This exception thrown while index view render:

"InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first."

This is index view :

@foreach (var item in Model) {
<tr>
    <td>

        @Html.DisplayFor(modelItem => item.pageGroup.GroupTitle)

    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Title)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ShortDescription)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Text)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ShowInSlider)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ImageName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Visit)
    </td>
    <td>
       
        @item.CreateData.ToShamsi();
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.PageID }) |
        @Html.ActionLink("Details", "Details", new { id=item.PageID }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.PageID })
    </td>
</tr> }

and the exeption thrown in this line :

@Html.DisplayFor(modelItem => item.pageGroup.GroupTitle)

where is the problem ?

If you are confused, tell me to put the codes of the section you want

this is my connection string :

<connectionStrings>
<add name="MyCmsContext" connectionString="data source=.;    initial catalog=MyCmsDB;persist security info=True;     Integrated Security=True; " providerName="System.Data.SqlClient" MultipleActiveResultSets="true"  />
Beginner
  • 27
  • 1
  • 5

1 Answers1

0

You need to allow MARS in your connection string. Add MultipleActiveResultSets=true to the provider part of your connection string.

"Server=xxxx;Database=xxxxx;xxxxx MultipleActiveResultSets=true"
Yinqiu
  • 6,609
  • 1
  • 6
  • 14
  • thanks for your answering . i add a code that you said but my context thrown new exception (System.TypeInitializationException: 'The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.' ) – Beginner Mar 19 '21 at 06:36
  • You can see this [thread](https://stackoverflow.com/questions/17585611/the-type-initializer-for-system-data-entity-internal-appconfig-threw-an-except) – Yinqiu Mar 19 '21 at 06:43
  • Hi @Beginner,Can you accept it as answer? – Yinqiu Mar 19 '21 at 06:59
  • Oh my god sorry i for got it – Beginner Mar 19 '21 at 10:21