C# 在windows启动时启动程序时无法打开sqlite数据库文件

C# 在windows启动时启动程序时无法打开sqlite数据库文件,c#,winforms,sqlite,windows-10,startup,C#,Winforms,Sqlite,Windows 10,Startup,我通过以下代码将程序设置为在启动时启动: Registry.CurrentUser .OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) .SetValue(Application.ProductName, Application.ExecutablePath); 重新启动Windows并登录到我的帐户(具有管理员权限)后,程序将成功运行,但当它尝试连接到sqlite文件

我通过以下代码将程序设置为在启动时启动:

Registry.CurrentUser
    .OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)
    .SetValue(Application.ProductName, Application.ExecutablePath);
重新启动Windows并登录到我的帐户(具有管理员权限)后,程序将成功运行,但当它尝试连接到sqlite文件时,会遇到以下异常:

"ClassName": "System.Data.DataException", "Message": "An exception occurred while initializing the database. See the InnerException for details.", "Data": null, "InnerException": { "ClassName": "System.Data.Entity.Core.EntityException", "Message": "The underlying provider failed on Open.", "Data": null, "InnerException": { "errorCode": 14, "ClassName": "System.Data.SQLite.SQLiteException", "Message": "unable to open database file", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.Data.SQLite.SQLite3.Open(String strFilename, String vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool) at System.Data.SQLite.SQLiteConnection.Open() at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<>c.<Open>b__13_0(DbConnection t, DbConnectionInterceptionContext c) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__55_0() at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) at System.Data.Entity.Core.EntityClient.EntityConnection.Open()", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nOpen\nSystem.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139\nSystem.Data.SQLite.SQLite3\nVoid Open(System.String, System.String, System.Data.SQLite.SQLiteConnectionFlags, System.Data.SQLite.SQLiteOpenFlagsEnum, Int32, Boolean)", "HResult": -2147481601, "Source": "System.Data.SQLite", "WatsonBuckets": null }, "HelpURL": null, "StackTraceString": " at System.Data.Entity.Core.EntityClient.EntityConnection.Open() at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass174_0.<ExecuteStoreCommand>b__0() at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreCommand(TransactionalBehavior transactionalBehavior, String commandText, Object[] parameters) at System.Data.Entity.Internal.InternalContext.ExecuteSqlCommand(TransactionalBehavior transactionalBehavior, String sql, Object[] parameters) at System.Data.Entity.Database.ExecuteSqlCommand(TransactionalBehavior transactionalBehavior, String sql, Object[] parameters) at SQLite.CodeFirst.SqliteDatabaseCreator.Create(Database db, DbModel model) at SQLite.CodeFirst.SqliteInitializerBase`1.InitializeDatabase(TContext context) at SQLite.CodeFirst.SqliteCreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass66_0`1.<CreateInitializationAction>b__0() at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nOpen\nEntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Data.Entity.Core.EntityClient.EntityConnection\nVoid Open()", "HResult": -2146233087, "Source": "EntityFramework", "WatsonBuckets": null }, "HelpURL": null, "StackTraceString": " at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() at System.Data.Entity.Internal.LazyInternalContext.<>c.<InitializeDatabase>b__58_0(InternalContext c) at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at Watcher.MainApplication..ctor() at Watcher.Program.Main()", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nPerformInitializationAction\nEntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Data.Entity.Internal.InternalContext\nVoid PerformInitializationAction(System.Action)", "HResult": -2146233087, "Source": "EntityFramework", "WatsonBuckets": null “ClassName”:“System.Data.DataException”, “消息”:“初始化数据库时发生异常。有关详细信息,请参阅InnerException。”, “数据”:空, “内部异常”:{ “ClassName”:“System.Data.Entity.Core.EntityException”, “消息”:“基础提供程序在打开时失败。”, “数据”:空, “内部异常”:{ “错误代码”:14, “ClassName”:“System.Data.SQLite.SQLiteException”, “消息”:“无法打开数据库文件”, “数据”:空, “InnerException”:null, “帮助URL”:空, “StackTraceString”: 在System.Data.SQLite.SQLite3.Open(字符串strFilename、字符串vfsName、SQLiteConnectionFlags connectionFlags、SQLiteOpenFlagsEnum openFlags、Int32 maxPoolSize、Boolean usePool) 在System.Data.SQLite.SQLiteConnection.Open()处 位于System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.c.b_u13_0(DbConnection t,DbConnectionInterceptionContext c) 在System.Data.Entity.Infrastructure.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget,Action`2 operation,TInterceptionContext interceptionContext,Action`3 executing,Action`3 executed) 位于System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext interceptionContext) 位于System.Data.Entity.Core.EntityClient.EntityConnection.b_u 55_0() 位于System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(操作操作) 在System.Data.Entity.Core.EntityClient.EntityConnection.Open()中, “RemoteStackTraceString”:空, “RemoteStackIndex”:0, “例外方法”:“8\nOpen\nSystem.Data.SQLite,Version=1.0.113.0,Culture=neutral,PublicKeyToken=db937bc2d44ff139\nSystem.Data.SQLite.SQLite3\nVoid Open(System.String,System.String,System.Data.SQLite.SQLiteConnectionFlags,System.Data.SQLite.sqliteopenflagsnum,Int32,Boolean)”, “HResult”:-2147481601, “Source”:“System.Data.SQLite”, “WatsonBuckets”:空 }, “帮助URL”:空, “StackTraceString”: 在System.Data.Entity.Core.EntityClient.EntityConnection.Open()中 位于System.Data.Entity.Core.Objects.ObjectContext.EnsureReconnection(布尔值shouldMonitorTransactions) 在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 Func,IDBEcutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess) 在System.Data.Entity.Core.Objects.ObjectContext.c__DisplayClass174_0.b__0()中 在System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1操作)中 位于System.Data.Entity.Core.Objects.ObjectContext.ExecuteStorommand(TransactionalBehavior TransactionalBehavior,String commandText,Object[]参数) 位于System.Data.Entity.Internal.InternalContext.ExecuteSqlCommand(TransactionalBehavior TransactionalBehavior,String sql,Object[]参数) 位于System.Data.Entity.Database.ExecuteSqlCommand(TransactionalBehavior,TransactionalBehavior,String sql,Object[]参数) 在SQLite.CodeFirst.SqliteDatabaseCreator.Create(数据库数据库数据库,数据库模型) 在SQLite.CodeFirst.SqliteInitializerBase`1.InitializeDatabase(TContext上下文) 在SQLite.CodeFirst.SqliteCreateDatabaseIfNotExists`1.InitializeDatabase(TContext上下文) 在System.Data.Entity.Internal.InternalContext.c__DisplayClass66_0`1.b__0()中 在System.Data.Entity.Internal.InternalContext.PerforminizationAction(Action Action)“, “RemoteStackTraceString”:空, “RemoteStackIndex”:0, “ExceptionMethod”:“8\nOpen\nEntityFramework,版本=6.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089\nSystem.Data.Entity.Core.EntityClient.EntityConnection\nVoid Open()”, “HResult”:-2146233087, “来源”:“EntityFramework”, “WatsonBuckets”:空 }, “帮助URL”:空, “StackTraceString”: 位于System.Data.Entity.Internal.InternalContext.PerforminizationAction(操作操作) 位于System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()处 在System.Data.Entity.Internal.LazyInternalContext.c.b_u58_0(InternalContext c)中 在System.Data.Entity.Internal.RetryAction`1.PerformAction(输入) 位于System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 Action) 在System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()中 位于System.Data.Entity.Internal.InternalContext.Initialize()处 位于System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型entityType) 位于System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 位于System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() 位于System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() 位于System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1源) 在Watcher.MainApplication..ctor()上 在Watcher.Program.Main()中, “RemoteStackTraceString”:空, “RemoteStackIndex”:0, “例外方法”:“8\nPerformInitializationAction\nEntityFramework,版本=6.0.0.0,区域性=neutral,PublicKeyToken=b77a5c561934e089\nSystem.Data.Entity.Internal.InternalContext\nVideo PerformilizationAction(System.Action)”, “HResult”:-2146233087, “来源”:“EntityFramework”, “WatsonBuckets”:空 当我手动运行程序时,此问题消失

我尝试使用文本文件而不是数据库,但由Windows运行的程序创建的文件与由手动运行的程序创建的文件不同


如何在windows 10上解决此问题?

在启动情况下重新启动并运行时,当前目录是系统目录。
所以我需要解决这个问题