45

In my mvc asp.net application, I am getting an error in edit function : in given code

public ActionResult Edit(int id)
{

      var res = (from r in objeEntities.DocumentationsSet.Include("DocStatus")
                where r.textid == id select r)
                .First();
}

I am getting this exception:

Source : System.Data.Entity

Stack Trace : 
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext
   context, ObjectParameterCollection parameterValues) 
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.b__0[TResult](IEnumerable`1 sequence) 
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.First[TSource](IQueryable`1 source)
at admin.com.Controllers.DocsGridController.Edit(Int32 id) in c:\Data\FinalCode\AC015\acomMVCSourceCode\admincom\Controllers\DocsController.cs:line
   307

Message : An error occurred while executing the command definition. See the inner exception for details.

This error is generated when I connect with remote server.

What is this error? How do I fix it?

4
  • 3
    "See the inner exception for details." Have you done that? What did it say? Oct 21, 2010 at 12:41
  • 6
    This happens to my apps quite a bit and it's usually a DB timeout. Jun 7, 2012 at 20:47
  • This is probably obvious, but the way to access the inner exception is from the exception object. Since I had a try block within a try block I mistakenly thought it was referring to the inner ... well, it was confusing for me. Jul 31, 2012 at 15:58
  • 1
    The inner exception for me indicated a failed mapping to some new tables I didn't even want. I recreated my model and selected the specific tables I wanted and the problem went away. Jul 31, 2012 at 15:59

9 Answers 9

63

Usually this means that your schema and mapping files are not in synch and there is a renamed or missing column someplace.

1
  • 1
    Lets see: mine was I removed Phone from View, but tried to reference it in a SELECT inside of a stored procedure. (sql server). Error was triggered inside the Stored Procedure not seeing the deleted column from the view.
    – JustJohn
    Mar 18, 2016 at 22:57
5

After spending hours, I found that I missed 's' letter in table name

It was [Table("Employee")] instead of [Table("Employees")]

3

This occurs when you specify the different name for repository table name and database table name. Please check your table name with database and repository.

2

In my case, I messed up the connectionString property in a publish profile, trying to access the wrong database (Initial Catalog). Entity Framework then complains that the entities do not match the database, and rightly so.

1

I had a similar situation with the 'An error occurred while executing the command definition' error. I had some views which were grabbing from another db which used current user security. The second db did not allow the login for the user of the first db causing this issue to occur. I added the db login to the server it was trying to get to from the original server and this fixed the issue. Check your views and see if there are any linked dbs which have different security than the db you are logging onto originally.

1

Does the actual query return no results? First() will fail if there are no results.

1
  • When edit action method is called, it has default parameter id, which can not be NULL never be Null Oct 21, 2010 at 10:00
0

Look at the Inner Exception and find out what object might have caused the problem, you might have changed its name.

0

I've just run into this issue and it was because I had updated a view in my DB and not refreshed the schema in my mapping.

0

In my case, It was from Stored Producers. I was removed a field from table and forgotten to remove it from my SP.

Not the answer you're looking for? Browse other questions tagged or ask your own question.