简体   繁体   English

使用SQL Server CE的Clickonce部署

[英]Clickonce deployment with SQL Server CE

I manage to finish my project and publish it for deployment on other machines. 我设法完成我的项目并将其发布以部署到其他计算机上。 My C# WPF application have SQL Server CE as its backend database. 我的C#WPF应用程序将SQL Server CE作为其后端数据库。 I wanted the database to be able to work in other machine that have no SQL Server CE installed. 我希望数据库能够在没有安装SQL Server CE的其他计算机上工作。 I publish it using clickonce, the publish was successful. 我使用clickonce发布,发布成功。 However when I run it on other machines, and tries to open the database there is an error prompt that said 'database file cannot be found. 但是,当我在其他计算机上运行它并尝试打开数据库时,出现错误提示,提示找不到“数据库文件”。 Check the path to the database [Data Source=D:db.sdf] . 检查数据库的路径[Data Source=D:db.sdf] I followed the tutorials on clickonce by mdsn, Microsoft and by other people, the result is always the same. 我遵循了mdsn,Microsoft和其他人关于clickonce的教程,结果始终是相同的。 The local database cannot be detected. 无法检测到本地数据库。

D:db.sdf is not created by ClickOnce, you must have changed something. D:db.sdf不是由ClickOnce创建的,您必须进行了一些更改。 ClickOnce by default installs data that is included in a project to a directory in the app folder, and sets the DataDirectory app domain value to the path to this directory. 默认情况下,ClickOnce会将项目中包含的数据安装到app文件夹中的目录中,并将DataDirectory应用程序域值设置为该目录的路径。 In your application you should use something like 在您的应用程序中,您应该使用类似

SqlConnection("Data Source=|DataDirectory|db.sdf;...")

Note that DataDirectory may not be writable by users. 请注意, DataDirectory可能无法被用户写入。 If you want users to save data you should copy |DataDirectory|db.sdf to some place writable like 如果希望用户保存数据,则应将|DataDirectory|db.sdf复制到可写的某个位置,例如

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

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

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