简体   繁体   English

如何在Windows Service中找到Compact数据库.sdf的路径?

[英]How to find path to compact database.sdf in Windows Service?

I have a solution with 3 projects: a WPF application, a setup and a Windows service. 我有3个项目的解决方案:WPF应用程序,安装程序和Windows服务。

In the WPF application I have a Database.sdf (SQL Server CE database) file. 在WPF应用程序中,我有一个Database.sdf (SQL Server CE数据库)文件。 When the application is installed for example in folder X there is also the database.sdf file in this folder. 例如,当将应用程序安装在文件夹X中时,此文件夹中也有database.sdf文件。

Now my problem is: I want to connect to this database from the Windows service, how can I find out where the application was installed so I can get the path to the .sdf file? 现在我的问题是:我想从Windows服务连接到该数据库,如何找到应用程序的安装位置,以便获取.sdf文件的路径?

您可以在安装WPF应用程序的过程中在HKLM中写一个注册表项,其中包含数据库文件的路径,然后Windows Service可以读取此项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM