Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 630
Aayushi Soni Avatar asked Oct 21 '10 09:10

Aayushi Soni


4 Answers

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

like image 163
John Farrell Avatar answered Nov 01 '22 05:11

John Farrell


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

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

like image 24
Joe Avatar answered Nov 01 '22 07:11

Joe


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.

like image 23
user2919069 Avatar answered Nov 01 '22 05:11

user2919069


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.

like image 33
j00hi Avatar answered Nov 01 '22 05:11

j00hi