Я пытаюсь создать веб-приложение, но найдено исключение EntityCommandExecutionException

#c# #visual-studio-2010 #asp.net-mvc-3

#c# #visual-studio-2010 #asp.net-mvc-3

Вопрос:

Я пытаюсь создать веб-приложение, но найдено исключение EntityCommandExecutionException, это мой класс контроллера

 namespace DemoMVC.Controllers
{
    public class ContactController : Controller
    {
            ContactContext db = new ContactContext();
            public ActionResult Index()
        {
            var contact = db.Contacts.ToList();
            return View(contact);
        }
        public ActionResult Details(int id)
        {
            return View();
        }
        public ActionResult Create()
        {
           return View();
        } 

        [HttpPost]
        public ActionResult Create(Contact person)
        {
            try
            {
                // TODO: Add insert logic here
                db.Contacts.Add(person);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Contact/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Contact/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Contact/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Contact/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
 

и это моя строка подключения

 <add name="ContactContext" connectionString="Data Source=RMSIPDB;Initial Catalog=CoroporateApps;User ID=CorApps;Password=CorApps_123" 
providerName="System.Data.SqlClient" />

And this is my View Page 
@model IEnumerable<DemoMVC.Models.Contact>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            Name
        </th>
        <th>
            Address
        </th>
        <th>
            Mobile
        </th>
        <th>
            DataDate
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Address)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Mobile)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DataDate)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}

</table> 
 

Пока я выполняю код, я получил исключение EntityCommandExecutionException, кто-нибудь может мне помочь.

Комментарии:

1. Что такое трассировка стека? Можете ли вы указать исходное исключение?

2. @RalphJansen StackTrace: в System.Data.EntityClient. Определение entitycommand. ExecuteStoreCommands(EntityCommand entityCommand, поведение CommandBehavior) в System.Data.Objects. Внутреннее. ObjectQueryExecutionPlan . Выполнить [TResultType](контекст ObjectContext, значения параметра ObjectParameterCollection) в System.Data.Objects. ObjectQuery 1.GetResults(Nullable 1 forMergeOption) в System.Data.Objects. ObjectQuery`1.System. Коллекции. Общий. IEnumerable<T>.GetEnumerator()

3. Можете ли вы установить точку останова? Правильно ли starturl?

4. @RalphJansen Да… но выполнение останавливается при public ActionResult Index() { var contact = db.Contacts . ToList(); возвращает представление (контакт); }

5. Можете ли вы проверить innerexception? Я думаю, что настоящая проблема именно в этом.