This is a migrated thread and some comments may be shown as answers.

GridView entity framework exception handling

3 Answers 107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Uwe
Top achievements
Rank 1
Uwe asked on 28 Nov 2012, 09:43 AM

Hello,


I’m using several DataGrids in an entity framework scenario.  In every case I’m using DB access and on every operations 
on QueryableEntityCollectionView<>  objects  I put them in a try – catch block.

But when my application is running and I just shutdown the SQL Server I get something terrible like this:

 

ClientConnectionId:00000000-0000-0000-0000-000000000000</ExceptionString><DataItems><Data><Key>HelpLink.ProdName</Key><Value>Microsoft SQL Server</Value></Data><Data><Key>HelpLink.EvtSrc</Key><Value>MSSQLServer</Value></Data><Data><Key>HelpLink.EvtID</Key><Value>10061</Value></Data><Data><Key>HelpLink.BaseHelpUrl</Key><Value>http://go.microsoft.com/fwlink<;/Value></Data><Data><Key>HelpLink.LinkId</Key><Value>20476</Value></Data></DataItems><InnerException><ExceptionType>System.ComponentModel.Win32Exception, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte</Message><StackTrace>   bei System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean&amp; closeStoreConnectionOnFailure)
   bei System.Data.EntityClient.EntityConnection.Open()
   bei System.Data.Objects.ObjectContext.EnsureConnection()
   bei System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   bei System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()
   bei System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   bei System.Data.Objects.ELinq.ObjectQueryProvider.&lt;GetElementFunction&gt;b__3[TResult](IEnumerable`1 sequence)
   bei System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   bei System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
   bei System.Linq.Queryable.Count[TSource](IQueryable`1 source)
   bei Telerik.Windows.Controls.EntityFramework.ObjectQueryProxy`1.RefreshCount()
   bei Telerik.Windows.Data.QueryableEntityCollectionView`1.CreateView()
   bei Telerik.Windows.Data.QueryableCollectionView.get_QueryableView()
   bei Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
   bei Telerik.Windows.Data.QueryableCollectionView.EnsureInternalList()
   bei Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
   bei Telerik.Windows.Data.QueryableCollectionView.get_InternalCount()
   bei Telerik.Windows.Data.QueryableCollectionView.get_Count()
   bei Telerik.Windows.Data.DataItemCollection.get_Count()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.RecreateItemMap()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.ResetGenerator()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.OnRefresh()
   bei Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.Refresh()
   bei Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
   bei Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   bei System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   bei System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
   bei System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   bei System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   bei System.Windows.Data.BindingExpression.Activate(Object item)
   bei System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement)
   bei System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   bei System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   bei System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
   bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   bei System.Windows.TreeWalkHelper.InvalidateTreeDependentProperty(TreeChangeInfo info, DependencyObject d, FrameworkObject&amp; fo, DependencyProperty dp, FrameworkPropertyMetadata fMetadata, Style selfStyle, Style selfThemeStyle, ChildRecord&amp; childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
   bei System.Windows.TreeWalkHelper.InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ChildRecord&amp; childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
   bei System.Windows.FrameworkElement.InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, Boolean isSelfInheritanceParent)
   bei System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
   bei System.Windows.TreeWalkHelper.OnAncestorChanged(FrameworkElement fe, FrameworkContentElement fce, TreeChangeInfo info)
   bei System.Windows.TreeWalkHelper.OnAncestorChanged(DependencyObject d, TreeChangeInfo info, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei MS.Internal.PrePostDescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   bei System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   bei System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   bei System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei MS.Internal.PrePostDescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   bei System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   bei System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   bei System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   bei System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   bei MS.Internal.PrePostDescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   bei System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode)
   bei System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
   bei System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent)
   bei System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
   bei System.Windows.Media.Visual.RemoveVisualChild(Visual child)
   bei System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
   bei System.Windows.StyleHelper.DetachGeneratedSubTree(FrameworkElement feContainer, FrameworkContentElement fceContainer)
   bei System.Windows.StyleHelper.ClearGeneratedSubTree(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, FrameworkTemplate oldFrameworkTemplate)
   bei System.Windows.StyleHelper.DoTemplateInvalidations(FrameworkElement feContainer, FrameworkTemplate oldFrameworkTemplate)
   bei System.Windows.StyleHelper.UpdateTemplateCache(FrameworkElement fe, FrameworkTemplate oldTemplate, FrameworkTemplate newTemplate, DependencyProperty templateProperty)
   bei System.Windows.Controls.ContentPresenter.OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   bei System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   bei System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   bei System.Windows.Controls.ContentPresenter.set_Template(DataTemplate value)
   bei System.Windows.Controls.ContentPresenter.EnsureTemplate()
   bei System.Windows.Controls.ContentPresenter.OnPreApplyTemplate()
   bei System.Windows.FrameworkElement.ApplyTemplate()
   bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   bei System.Windows.UIElement.Measure(Size availableSize)
   bei System.Windows.ContextLayoutManager.UpdateLayout()
   bei System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   bei System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   bei System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   bei System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   bei System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.DispatcherOperation.InvokeImpl()
   bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Windows.Threading.DispatcherOperation.Invoke()
   bei System.Windows.Threading.Dispatcher.ProcessQueue()
   bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
   bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   bei MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
   bei System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG&amp; msg)
   bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   bei System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   bei System.Windows.Threading.Dispatcher.Run()
   bei System.Windows.Application.RunDispatcher(Object ignore)
   bei System.Windows.Application.RunInternal(Window window)
   bei System.Windows.Application.Run(Window window)
   bei System.Windows.Application.Run()
   bei FuelOPTBA20.App.Main()
   bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()
</StackTrace><ExceptionString>System.ComponentModel.Win32Exception (0x80004005): Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte</ExceptionString><NativeErrorCode>274D</NativeErrorCode></InnerException></InnerException></Exception></TraceRecord>


the application quits and the call stack in the Debugger is empty. Is there a way to prevent this?

Best Regarts
Uwe

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 29 Nov 2012, 01:42 PM
Hi,

It seems that your solution tries to open a connection, but it cannot because you have shutdown the SQL Server. The error message means that no connection could be established because the target machine actively refused it.

Have you tried not opening the connection or using a Try/Catch clause for example?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Uwe
Top achievements
Rank 1
answered on 29 Nov 2012, 01:59 PM
Hello Didie,

thanks you for your effort , I'm afraid my description is misleading.
I shut down the SQL-Server  with intent, to test what will happen. In any suitable location in my source code
 I'm using a catch try block, but still I get this exception and I have no idea which part of the source code throws it.

Greetings Uwe

0
Vlad
Telerik team
answered on 29 Nov 2012, 02:09 PM
Hi,

 You will get such exception with any UI component (or anything else) that will try to enumerate the query and when the connection is not valid. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Uwe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Uwe
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or