C# 无法在windows启动Wpf上打开数据库 我想在windows启动中打开我的应用程序,但在windows启动中出现错误 说无法打开数据库,我在应用程序由用户启动时使用了sqlite数据库。它工作正常,应用程序可以找到数据库,但在windows启动时它无法 我无法打开数据库 下面是我用于db连接字符串的代码 SQLiteConnection connection = new SQLiteConnection("Data Source=.\\notes_db.db;");
以及windows启动代码:C# 无法在windows启动Wpf上打开数据库 我想在windows启动中打开我的应用程序,但在windows启动中出现错误 说无法打开数据库,我在应用程序由用户启动时使用了sqlite数据库。它工作正常,应用程序可以找到数据库,但在windows启动时它无法 我无法打开数据库 下面是我用于db连接字符串的代码 SQLiteConnection connection = new SQLiteConnection("Data Source=.\\notes_db.db;");,c#,wpf,C#,Wpf,以及windows启动代码: try { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Assembly curAssembly = Assembly.GetEx
try
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
Assembly curAssembly = Assembly.GetExecutingAssembly();
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
如果你知道我如何得到它,请告诉我。谢谢。将当前目录设置为应用程序的文件夹 类似这样,未经测试:
Enviorment.CurrentDirectory = Path.GetPath(Process.GetCurrentProcess().MainModule.FileName);
当注册表启动应用程序时。它使用system32作为当前目录。谢谢你的回答,我解决了我的问题。我得到了我的应用程序的位置,并将其设置为连接字符串,它就工作了
SQLiteConnection connection = new SQLiteConnection("Data Source=.\\notes_db.db;");