none
Getting a "The process was terminated due to an unhandled exception" error, but only from the app RRS feed

  • Question

  • We're working on developing a WPF app. We use Entity Framework (version 6). Normally create .EDMX files against the databases we develop apps for. We also use Windows Authentication for all of our development. However, with this app there's some strange behavior. I develop on two machines - a Windows 10 Enterprise desktop and a Windows 10 Enterprise laptop. I've found that I can develop and debug it on the desktop. However, when I generated a deployment of the app using TFS, I cannot run it. When I run it on the desktop (not debugging with Visual Studio) it crashes so fast that it doesn't come up at all. I thought at first it might be because the app is so new and that we didn't have any data. But I did see, when I looked at the Windows Event Viewer, that there was some SQL Server error.

    Today I'm working from the laptop. On this machine I simply cannot run it at all. Not from Visual Studio and not just running it. The behavior is the same; it crashes immediately. And the error in Windows Event Viewer is the same as running it on the desktop. Here is the text of the error from the Event Viewer:

    Log Name:      Application
    Source:        .NET Runtime
    Date:          8/15/2019 11:29:43 AM
    Event ID:      1026
    Task Category: None
    Level:         Error
    Keywords:      Classic
    User:          N/A
    Computer:      MYCOMPUTER
    Description:
    Application: PharmacyWarehouse.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.ComponentModel.Win32Exception
    Exception Info: System.Data.SqlClient.SqlException
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(System.Data.ProviderBase.DbConnectionPoolIdentity, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SqlCredential, System.Object, System.String, System.Security.SecureString, Boolean, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SessionData, System.Data.ProviderBase.DbConnectionPool, System.String, Boolean, System.Data.SqlClient.SqlAuthenticationProviderManager)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Object, System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Data.Common.DbConnectionOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, UInt32, Boolean, Boolean, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal, System.Data.ProviderBase.DbConnectionInternal ByRef)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
       at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbConnectionInterceptionContext)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Dispatch[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon, System.Action`2<System.__Canon,System.__Canon>, System.__Canon, System.Action`3<System.__Canon,System.__Canon,System.__Canon>, System.Action`3<System.__Canon,System.__Canon,System.__Canon>)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(System.Data.Common.DbConnection, System.Data.Entity.Infrastructure.Interception.DbInterceptionContext)
       at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy+<>c__DisplayClass1.<Execute>b__0()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Func`1<System.__Canon>)
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(System.Action)
       at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
    Exception Info: System.Data.Entity.Core.EntityException
       at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
       at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean)
       at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Func`1<System.__Canon>, System.Data.Entity.Infrastructure.IDbExecutionStrategy, Boolean, Boolean)
       at System.Data.Entity.Core.Objects.ObjectQuery`1+<>c__DisplayClass7[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<GetResults>b__5()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Func`1<System.__Canon>)
       at System.Data.Entity.Core.Objects.ObjectQuery`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetResults(System.Nullable`1<System.Data.Entity.Core.Objects.MergeOption>)
       at System.Data.Entity.Core.Objects.ObjectQuery`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
       at System.Data.Entity.Internal.LazyEnumerator`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
       at System.Collections.Generic.List`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
       at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
       at PharmacyWarehouse.App..ctor()
       at PharmacyWarehouse.App.Main()

    As you can see from the error listing above, an exception occurred in System.Data.Entity.Core.EntityException. Since it referenced EntityException, I took a look at the App.xaml.cs file. We didn't have any try-catch block around some instantiations of two of our EF entities. So, I wrapped a try-catch block around them and debugged it. This time I was able to see where it was failing. Here's the code snippet:

    try
    {
    	_MainDataContext = new AppEntities();
    	using (var context = new CoreFrameworkEntities())
    	{
    		DataDictionary = context.vwDataDictionaries.ToList();
    	}
    }
    catch (Exception ex)
    {
    
    	throw;
    }
    

    It's failing on the line DataDictionary = context.vwDataDictionaries.ToList(); When I stepped into the catch, I examined the exception variable ex. That revealed another innerexception, which isn't in the error above. This exception showed that I was experiencing an access violation. However, I am having a hard time believing this, because as I said we use Windows authentication. In the App.Config file the connection string as integrated security set to true. And finally, I can easily open up SSMS and query the vwDataDirectionaries fine.

    So, what's causing this access violation? What can I do about it?


    Rod

    Thursday, August 15, 2019 7:36 PM

All replies

  • All desptop programs run under the context of the loggoed on user logged in on  the Windows O/S. if the user account doesn't have the permissions to access the resource, then it's access denied. You can run the program with admin rights and see what happens, or you can enable the hidden super admin account and run the program under that account.
    Thursday, August 15, 2019 9:00 PM
  • That was a good idea; one that I hadn't thought of trying. I tried to find a way to launch Visual Studio as Administrator, but couldn't. So I rebuilt the project, found it with File Explorer and ran as Administrator. I got the same error. However, yesterday I added a quick-and-dirty routine to capture the error in the constructor or App (in App.xaml.cs). Here's what it showed me:

    Error trying to fetch data from a view using EF

    I'm hoping this will be more revealing as to what's going on.


    Rod

    Friday, August 16, 2019 2:27 PM
  • It seems as though MS SQL Server has not been configured  to allow the Named Pipes protocol, which is inter- process communications.

    You can post to the MSDN SQL Server fourm for help.

    Friday, August 16, 2019 9:18 PM
  • I checked with the DBA. He said that Named Pipes protocol is configured.

    Rod

    Sunday, August 18, 2019 2:34 PM