Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityCommandExecutionException when returning a PagedList
    primarykey
    data
    text
    <p><strong>Edit: I've solved the original problem, but it gives rise to another question</strong></p> <p>The problem was with this line</p> <pre><code>&amp;&amp; (logLevel == "All" || logLevel == "Error") </code></pre> <p>The LINQ query in 'list' generated the following SQL</p> <pre><code>SELECT 0 AS [C1], N'guid' AS [C2], [Extent1].[ErrorId] AS [ErrorId], [Extent1].[TimeUtc] AS [TimeUtc] FROM [ELMAH_Error] AS [Extent1] WHERE ([Extent1].[TimeUtc] &gt;= @p__linq__0) AND ([Extent1].[TimeUtc] &lt;= @p__linq__1) AND ((N'All' = @p__linq__2) OR (N'Error' = @p__linq__3)) </code></pre> <p>The error I was getting (Inner exception = "p_linq_2 : String truncation: max=3, len=5, value='Error'.") was caused by this part of the SQL</p> <pre><code>(N'All' = @p__linq__2) </code></pre> <p>When I removed logLevel == "All" from the LINQ query, the error disappeared.</p> <p><strong>So, my question now is - why is LINQ/SQL attempting to truncate p_linq__2? It is performing a comparison... why did it need to truncate?</strong></p> <hr> <p><strong>Original Question</strong></p> <p>I'm integrating Elmah and Log4Net with my existing MVC application (following this guide - <a href="http://www.codeproject.com/Articles/104112/Log-Reporting-Dashboard-for-ASP-NET-MVC" rel="nofollow">http://www.codeproject.com/Articles/104112/Log-Reporting-Dashboard-for-ASP-NET-MVC</a>). I'm using SQL CE 4. Handled and unhandled errors ARE being logged to the database, the issue I am having is with the UI to view the errors </p> <p>I am getting an EntityCommandExecutionException triggered by this line (full method listing below)</p> <pre><code>return new PagedList&lt;LogEvent&gt;(list, pageIndex, pageSize); </code></pre> <ul> <li>Error message = "An error occurred while executing the command definition. See the inner exception for details." </li> <li>Inner exception = "p_<em>linq</em>_2 : String truncation: max=3, len=5, value='Error'."</li> </ul> <p>From what I can see, 'list' is populated OK.. </p> <p>The method where the error originates</p> <pre><code>public IPagedList&lt;LogEvent&gt; GetByDateRangeAndType(int pageIndex, int pageSize, DateTime start, DateTime end, string logProviderName, string logLevel) { IQueryable&lt;LogEvent&gt; list = null; switch (logProviderName) { case "All": foreach (string providerName in logProviders.Keys) { IQueryable&lt;LogEvent&gt; logList = GetProvider(providerName).GetByDateRangeAndType(pageIndex, pageSize, start, end, logLevel); list = (list == null) ? logList : list.Union(logList); } break; default: list = GetProvider(logProviderName).GetByDateRangeAndType(pageIndex, pageSize, start, end, logLevel); break; } list = list.OrderByDescending(d =&gt; d.LogDate); return new PagedList&lt;LogEvent&gt;(list, pageIndex, pageSize); } </code></pre> <p>The method it calls</p> <pre><code>private ILogReportingRepository GetProvider(string logProviderName) { string logSourceType = logProviders[logProviderName]; Type providerType = Type.GetType(logSourceType); ILogReportingRepository provider = Activator.CreateInstance(providerType, _context) as ILogReportingRepository; return provider; } </code></pre> <p>The chained method</p> <pre><code>public IQueryable&lt;LogEvent&gt; GetByDateRangeAndType(int pageIndex, int pageSize, DateTime start, DateTime end, string logLevel) { IQueryable&lt;LogEvent&gt; list = (from a in _context.ELMAH_Error where a.TimeUtc &gt;= start &amp;&amp; a.TimeUtc &lt;= end &amp;&amp; (logLevel == "All" || logLevel == "Error") select new LogEvent { IdType = "guid" , Id = "" , IdAsInteger = 0 , IdAsGuid = a.ErrorId , LoggerProviderName = "Elmah" , LogDate = a.TimeUtc , MachineName = a.Host , Message = a.Message , Type = a.Type , Level = "Error" , Source = a.Source, StackTrace = "" }); return list; } </code></pre> <p>Stack trace</p> <p>[InvalidOperationException: p_<em>linq</em>_2 : String truncation: max=3, len=5, value='Error'.] System.Data.SqlServerCe.SqlCeCommand.FillParameterDataBindings(Boolean verifyValue) +1670 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +397 System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior) +59 System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteReader(CommandBehavior behavior) +342 System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteDbDataReader(CommandBehavior behavior) +41 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +437</p> <p>[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.] System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +507 System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +675 System.Data.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1 forMergeOption) +102 System.Data.Objects.ObjectQuery<code>1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator() +30 System.Linq.Enumerable.Single(IEnumerable</code>1 source) +100 System.Data.Objects.ELinq.ObjectQueryProvider.b__3(IEnumerable<code>1 sequence) +5 System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable</code>1 query, Expression queryRoot) +25 System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +70 System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +82 System.Linq.Queryable.Count(IQueryable<code>1 source) +233 MvcPaging.PagedList</code>1..ctor(IQueryable<code>1 source, Int32 index, Int32 pageSize, Nullable</code>1 totalCount) +532 IDSM.Repository.LogReportingFacade.GetByDateRangeAndType(Int32 pageIndex, Int32 pageSize, DateTime start, DateTime end, </p> <hr>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload