简体   繁体   English

部署实体框架WPF应用程序

[英]Deploying Entity Framework WPF Application

I've made a WPF application that uses EF6 code first database. 我已经制作了使用EF6代码优先数据库的WPF应用程序。 I've been doing it all in Visual Studio and using the default LocalDb. 我一直在Visual Studio中使用默认的LocalDb进行所有操作。 The client wants to test what i've doe so far. 客户想要测试到目前为止我所做的事情。 I've tried ClickOnce application installation to my development PC. 我已经尝试将ClickOnce应用程序安装到我的开发PC上。 The program simply doesn't start, no window opens.... absolutely nothing happens. 该程序根本无法启动,没有窗口打开。 I've deployed a simple WPF app and it works right away so i surmise it's the EF component. 我已经部署了一个简单的WPF应用程序,并且可以立即运行,因此我推测它是EF组件。

  • How do i get some sort of output log, or debugging so i can see what the error is? 我如何获取某种输出日志或调试信息,以便查看错误原因?
  • Any ideas on how to fix the error? 关于如何解决错误的任何想法?
  • Where does it get installed to? 它安装在哪里?
  • How can i attach the debugger? 我如何连接调试器?

MY CONNECTION DETAILS from App.config 来自App.config的我的连接详细信息

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="EEHA_Inspector.Properties.Settings.EEHA_Inspector_Model_EEHA_DbContextConnectionString"
      connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=EEHA_Inspector.Model.EEHA_DbContext;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Any help would be greatly appreciated. 任何帮助将不胜感激。

UPDATE #2 - Windows Log Exception 更新#2-Windows日志异常

Application: EEHA_Inspector.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
   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.Linq.Enumerable.FirstOrDefault[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Linq.Expressions.Expression)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.Expressions.Expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.Expressions.Expression)
   at System.Linq.Queryable.FirstOrDefault[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.IQueryable`1<System.__Canon>)
   at System.Data.Entity.Internal.EdmMetadataRepository.QueryForModelHash(System.Func`2<System.Data.Common.DbConnection,System.Data.Entity.Internal.EdmMetadataContext>)
   at System.Data.Entity.Internal.InternalContext.QueryForModelHash()
   at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(System.Data.Entity.Internal.InternalContext, System.Data.Entity.Internal.ModelHashCalculator, Boolean, System.Data.Entity.Internal.DatabaseExistenceState)
   at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean, System.Data.Entity.Internal.DatabaseExistenceState)
   at System.Data.Entity.CreateDatabaseIfNotExists`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InitializeDatabase(System.__Canon)
   at System.Data.Entity.Internal.InternalContext+<>c__DisplayClassf`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<CreateInitializationAction>b__e()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(System.Action)

Exception Info: System.Data.DataException
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(System.Action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(System.Data.Entity.Internal.InternalContext)
   at System.Data.Entity.Internal.RetryAction`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].PerformAction(System.__Canon)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(System.Action`1<System.Data.Entity.Internal.InternalContext>)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(System.Type)
   at System.Data.Entity.Internal.Linq.InternalSet`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Where[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.IQueryable`1<System.__Canon>, System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,Boolean>>)
   at EEHA_Inspector.Model.LoadObvCollection+<Equips>d__4.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   at EEHA_Inspector.ViewModel.EquipRegVm+<Load>d__55.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at EEHA_Inspector.App.Main()

UPDATE #2 - Windows Log Information 更新#2-Windows日志信息

Fault bucket 129273820369, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: EEHA_Inspector.exe
P2: 1.0.0.0
P3: 58222f01
P4: System.Data
P5: 4.6.1586.0
P6: 575a1428
P7: 29fe
P8: 108
P9: System.Data.DataException
P10: 

Attached files:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERCB7E.tmp.WERInternalMetadata.xml

These files may be available here:
C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_EEHA_Inspector.e_11252b12b7f6697437e3ba42fb9b6e25caa6b8_5e1d3f42_3a80d3bb

Analysis symbol: 
Rechecking for solution: 0
Report Id: 91f3e855-2996-40fe-b5fd-957527bbdc9d
Report Status: 0
Hashed bucket: f5ea3fa3886ba4e09d8362936de86fe8

UPDATE #2 -Application Error in Windows Log 更新#2-Windows日志中的应用程序错误

Faulting application name: EEHA_Inspector.exe, version: 1.0.0.0, time stamp: 0x58222f01
Faulting module name: KERNELBASE.dll, version: 10.0.14393.0, time stamp: 0x57898e34
Exception code: 0xe0434352
Fault offset: 0x000d96c2
Faulting process id: 0x5458
Faulting application start time: 0x01d239ffc4803847
Faulting application path: C:\Users\agibson\AppData\Local\Apps\2.0\1RVHJ9WW.8JB\BDB4M51Q.L3R\eeha..tion_fe2d9ab6a328f11f_0001.0000_19df975805717e2b\EEHA_Inspector.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 91f3e855-2996-40fe-b5fd-957527bbdc9d
Faulting package full name: 
Faulting package-relative application ID: 

UPDATE 3 =================================================== 更新3 ================================================= ===

OnModelOveride in the DbContext DbContext中的OnModelOveride

namespace EEHA_Inspector.Model
{

    /// <summary>
    /// Database Definition.
    /// </summary>
    public class EEHA_DbContext : DbContext
    {
...............
/// <summary>
        /// Fluent API - Entity Building Configuration. Used to define extra conditions when building the model.
        /// These are more powerful than data annotations but also more complex.
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            /* FLUENT API MODEL OVERIDE - INTERMEDIARY TABLES
             *  Creates an intermediate mapping tables to hold many-to-many relationships between
             *  two tables. This is since one table can have multiple objects from another table.
             *  This intermediate table is used just as a look up table.
             *  Although its a look up table, databases must be configured to show the link two ways 
             *  since its not possible to have a many-to-many unidirectional relationship.
             *  By mapping these intermediary table; the lookup table stays clear of the relationship;
             *  while this intermediary table handles the needed mapping to make it possible.
             *  E.g. An Equip object contains a collection of Protections; while a Protection
             *  does not contain any reference to an Equip; since this is handled in a 3rd mapping table,
             *  created by these Fluent API model builder commands. */

            // Equipment Many-To-Many Look Up to ProtectionCodes
            modelBuilder.Entity<Equip>()
            .HasMany(e => e.Protections)
            .WithMany()
            .Map(x =>
            {
                x.MapLeftKey("EquipId");
                x.MapRightKey("ProtectionId");
                x.ToTable("EquipMapToProtections");
            });

            // InspectCheck Many-To-Many Look Up to InspectGrades
            modelBuilder.Entity<InspectCheck>()
            .HasMany(i => i.InspectGrades)
            .WithMany()
            .Map(x =>
            {
                x.MapLeftKey("InspectCheckId");
                x.MapRightKey("InspectGradeId");
                x.ToTable("InspectCheckMapToInspectGrades");
            });
        }


    }
}

UPDATE 3.1 Initialiser Setup UPDATE 3.1初始化程序设置

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            // Set the database initializer
            Database.SetInitializer<EEHA_DbContext>(new EEHA_DbInit());
        }
}

SEED OVERIDE 种子超过

#if DEBUG
#define DESTROY_DB_ONSTART //TODO remove when development progresses. Will make the database get dropped upon every start up
#endif
namespace EEHA_Inspector.Model
{
    /// <summary>
    /// Custom Initialiser for the HA Database.
    /// Set the initialiliser in the App.xaml.cs class contructor (make one if not there).
    ///  <code>Database.SetInitializer<EEHA_DbContext>(new EEHA_DbInit());</code>
    /// </summary>
#if DESTROY_DB_ONSTART
    class EEHA_DbInit : DropCreateDatabaseAlways<EEHA_DbContext>
#else
    class EEHA_DbInit : CreateDatabaseIfNotExists<EEHA_DbContext>
#endif
    {

#if DESTROY_DB_ONSTART
        /// <summary>
        /// Overide the Initialize to force a close of all connections when in testing
        /// </summary>
        /// <param name="Db">The DbContext to operate on.</param>
        public override void InitializeDatabase(EEHA_DbContext Db)
        {
#if DEBUG
            this.KillAllConnections(Db);
#endif
            base.InitializeDatabase(Db);
        }
#endif


        protected override void Seed(EEHA_DbContext Db)
        {
.....changes to Db
Db.SaveChanges();
base.Seed(Db);
Db.SaveChanges(); //TODO needed?
}

UPDATE 4 - Using DbConfig Earlier today i ran the SQLExpress install manually and just went with the defaults for all options. 更新4-使用DbConfig今天早些时候,我手动运行了SQLExpress安装,并且所有选项都使用默认值。 I've converted to DbConfig based on what i could find on the msdn update. 我已经根据我在msdn更新中可以找到的内容转换为DbConfig。 This works again in visual studio. 这可以在Visual Studio中再次使用。 Making the Db at the name i gave to the DbContext Constructor. 以我提供给DbContext构造函数的名称来制作Db。 Just to be sure i uninstalled the programs ClickOnce install. 只是为了确保我卸载了ClickOnce安装程序。 Reinstalled. 重新安装。 When i was fiddling earlier i noticed this, but i now get a dialog box saying "Cannot Start Application || Application cannot be started. Contact the application Vendor". 当我较早摆弄时,我注意到了这一点,但是现在我看到一个对话框,提示“无法启动应用程序||无法启动应用程序。请与应用程序供应商联系”。 Unlike earlier where the app would run and then crash. 与之前的应用会运行然后崩溃的情况不同。 This new way gives me no custom exception log, but i do get details shown below: 这种新方法没有给我任何自定义异常日志,但我确实获得了如下所示的详细信息:

Cannot Start Application Error - Details button .log 无法启动应用程序错误-详细信息按钮.log

PLATFORM VERSION INFO
    Windows             : 10.0.14393.0 (Win32NT)
    Common Language Runtime     : 4.0.30319.42000
    System.Deployment.dll       : 4.6.1586.0 built by: NETFXREL2
    clr.dll             : 4.6.1586.0 built by: NETFXREL2
    dfdll.dll           : 4.6.1586.0 built by: NETFXREL2
    dfshim.dll          : 10.0.14393.0 (rs1_release.160715-1616)

SOURCES
    Deployment url          : file:///C:/TempPath/EEHA/EEHA_Inspector.application

IDENTITIES
    Deployment Identity     : EEHA_Inspector.application, Version=1.0.0.17, Culture=neutral, PublicKeyToken=fe2d9ab6a328f11f, processorArchitecture=msil

APPLICATION SUMMARY
    * Installable application.

ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * Activation of C:\TempPath\EEHA\EEHA_Inspector.application resulted in exception. Following failure messages were detected:
        + External component has thrown an exception.

COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

WARNINGS
    There were no warnings during this operation.

OPERATION PROGRESS STATUS
    * [9/11/2016 8:03:58 PM] : Activation of C:\TempPath\EEHA\EEHA_Inspector.application has started.
    * [9/11/2016 8:03:58 PM] : Processing of deployment manifest has successfully completed.

ERROR DETAILS
    Following errors were detected during this operation.
    * [9/11/2016 8:03:58 PM] System.Runtime.InteropServices.SEHException
        - External component has thrown an exception.
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Internal.Isolation.IStateManager.Scavenge(UInt32 Flags, UInt32& Disposition)
            at System.Deployment.Application.ComponentStore.SubmitStoreTransaction(StoreTransactionContext storeTxn, SubscriptionState subState)
            at System.Deployment.Application.ComponentStore.SetPendingDeployment(SubscriptionState subState, DefinitionIdentity deployId, DateTime checkTime)
            at System.Deployment.Application.SubscriptionStore.SetLastCheckTimeToNow(SubscriptionState subState)
            at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)

COMPONENT STORE TRANSACTION DETAILS
    * Transaction at [9/11/2016 8:03:58 PM]
        + System.Deployment.Internal.Isolation.StoreOperationSetDeploymentMetadata
            - Status: Set
            - HRESULT: 0x0
        + System.Deployment.Internal.Isolation.StoreTransactionOperationType (27)
            - HRESULT: 0x0

Db Context Constructor Db上下文构造器

public EEHA_DbContext() : base("TestEEHACodeDb")
    {

    }

The DbConfig Class DbConfig类别

namespace EEHA_Inspector.Model
{
    public class EEHA_DbConfig : DbConfiguration
    {
        public EEHA_DbConfig()
        {
            SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
            SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
        }
    }
}

App.config Removed connection string. App.config删除的连接字符串。 Do i remove more? 我要删除更多吗?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <!--<connectionStrings>
    <add name="EEHA_Inspector.Properties.Settings.EEHA_Inspector_Model_EEHA_DbContextConnectionString"
      connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=EEHA_Inspector.Model.EEHA_DbContext;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    --><!--<add name="EEHA_Inspector.Properties.Settings.EEHA_Inspector_Model_EEHA_DbContextConnectionString"
     connectionString="Data Source=./SQLEXPRESS;Initial Catalog=EEHA_Inspector.Model.EEHA_DbContext;Integrated Security=True"
     providerName="System.Data.SqlClient" />--><!--
  </connectionStrings>-->
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">-->
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

SOLUTION/ / WRAP UP Thanks to grek40. 解决方案/ /打包感谢grek40。 Particularly his exception catching code. 特别是他的异常捕获代码。 This allowed me to start making changes to find the errors. 这使我可以开始进行更改以查找错误。 Prior to that, the windows logs didn't help at all. 在此之前,Windows日志根本没有帮助。 What put me past the hurdle was using the DbContext definition he suggested. 让我克服障碍的是使用他建议的DbContext定义。 For some reason using the default DbContext constructor and a connection string seemed to make ClickOnce install expect to find an mdf file; 由于某种原因,使用默认的DbContext构造函数和连接字符串似乎会使ClickOnce安装期望找到一个mdf文件。 even though attaching one wasn't specified. 即使未指定附加附件。 The exception catch code also allowed my my debugging in release mode to find some odd exceptions (once that didn't apply to debug mode, or that made any sense to me). 异常捕获代码还使我在发布模式下的调试可以找到一些奇怪的异常(一次不适用于调试模式,或者对我来说没有任何意义)。 I've now turned off the offending code so i could proceed; 我现在关闭了有问题的代码,因此我可以继续进行; the click once install now works. 单击一次安装即可使用。

I want to make sure that you actually do everything possible to catch and log the occuring exception. 我想确保您确实尽一切可能捕获并记录发生的异常。

Make sure to register an exception handler in App.xaml with DispatcherUnhandledException 确保使用DispatcherUnhandledExceptionApp.xaml注册异常处理程序

<Application
    x:Class="[Your Stuff]"
    DispatcherUnhandledException="Application_DispatcherUnhandledException">
</Application>

Implement some logging in the handler (inside App.xaml.cs ). 在处理程序中实现一些日志记录(在App.xaml.cs内部)。 It should be something that summarizes the exception messages of all inner exceptions as well as their stack traces. 它应该是对所有内部异常的异常消息及其堆栈跟踪进行汇总的内容。 Just write that information to some sort of log file ( C:\\Temp\\MyAppCrashes.log in my example). 只需将该信息写入某种日志文件(在我的示例中为C:\\Temp\\MyAppCrashes.log )。

private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    var sb = new StringBuilder();

    AppendExceptionMessages(sb, e.Exception);
    AppendExceptionStacktraces(sb, e.Exception);

    File.AppendAllText(@"C:\Temp\MyAppCrashes.log", sb.ToString());
}

private void AppendExceptionMessages(StringBuilder sb, Exception e)
{
    while (e != null)
    {
        sb.AppendLine("============== Exception ===============").AppendLine(e.Message);
        e = e.InnerException;
    }
}
private void AppendExceptionStacktraces(StringBuilder sb, Exception e)
{
    while (e != null)
    {
        sb.AppendLine("======== Exception Stacktrace ==========").AppendLine(e.StackTrace);
        e = e.InnerException;
    }
}

I hope this reveals some more information, if it's not enough, make sure to register a Startup handler in App.xaml instead of a StartupUri . 我希望这能揭示更多信息,如果还不够,请确保在App.xaml注册一个Startup处理程序,而不是StartupUri In the startup, before creating any window, create an instance of your db context, call db.Database.Exists() and db.Database.Initialize(true) , make sure to check the Exists return value and wrap the calls in try-catch . 在启动过程中,在创建任何窗口之前,请创建您的数据库上下文的实例,调用db.Database.Exists()db.Database.Initialize(true) ,确保检查Exists返回值并将这些调用包装在try-catch Ofcourse, write logging details if any exception is caught. 当然,如果捕获到任何异常,请写日志详细信息。

So far for now, hope you find anything with that approach. 到目前为止,希望您能找到使用该方法的任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署使用Entity Framework Core的WPF应用程序 - Deploying a WPF application that uses Entity Framework Core Bin-在WPF中部署基于MySQL Entity Framework Provider的应用程序? - Bin - deploying a MySQL Entity Framework Provider - based application in WPF? 使用实体框架部署MVC 4应用程序 - Deploying MVC 4 Application with Entity Framework 数据网格,实体框架WPF应用程序中的“更新”按钮 - Update button in datagrid, entity framework WPF Application 实体框架 - WPF / MVVM应用程序中的基础结构 - Entity Framework - infrastructure in WPF/MVVM application 部署WPF浏览器应用程序时如何提示安装.NET Framework? - How to prompt to install .NET Framework when deploying a WPF Browser Application? 部署使用Entity Framework的应用程序并在客户端计算机上创建数据库 - Deploying my application that uses Entity Framework and creating databases on the client machine 将WPF应用程序迁移到.net Framework 4.5.1之后的实体框架异常 - Entity Framework exception after migrating WPF application to .net Framework 4.5.1 使用数据库部署 WPF 应用程序 - Deploying WPF Application with database 具有实体框架的WPF应用程序,app.config的正确设置 - WPF application with Entity Framework, proper settings for app.config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM