启动应用程序时无法打开 Sqllite DB 文件
我使用 PostBuildevnt 脚本启动申请表链接
http://blogs.msdn.com/b/astebner/archive/2006/08/12/696833.aspx?wa=wsignin1.0&CommentPosted=true
并成功启动应用程序.我正在使用 sqllite 作为应用程序。 我在应用程序文件夹/数据库中添加了 DB 文件,并使用以下代码打开 Db 文件。
string ConnectionString = "data source=" + Path.GetFullPath(".") + "\\DataBase\\CATTDB.db";
如果我从安装向导启动应用程序,它不会连接到数据库文件。它会抛出类似“无法打开文件”的错误。
如果我从开始菜单或桌面图标启动,它工作正常..
这里有什么问题? 请帮我..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从安装程序启动时,您的工作目录可能会有所不同...
在这种情况下,
Path.GetFullPath(".")
返回什么(记录和/或显示值)?始终存在权限/权限问题 - 取决于您的操作系统(即 Windows 7...)和运行应用程序的用户(ia 管理员?)出于安全原因,您不允许在应用程序目录中写入。如果您需要读+写的地方,您应该使用 http://msdn.microsoft.com/de-de/library/system.windows.forms.application.userappdatapath.aspx
只需检查数据库是否在该路径中 - 如果不是复制它在那里 - 并在那里使用它...
其他位置可能是来自 http://msdn.microsoft.com/de-de/library/14tx8hby.aspx 和 http://msdn.microsoft.com/de-de/library/system.environment.specialfolder.aspx
It could be that your working directoy is different when started from the installer...
What does
Path.GetFullPath(".")
return in this case (log and/or display the value)?There is always the issue of permission/rights - depending on your OS (i.e. Windows 7...) and the user your running the app with (i.a. Administrator?) for security reasons you are not allowed to write in the application directory... if you need someplace with read+write you should use http://msdn.microsoft.com/de-de/library/system.windows.forms.application.userappdatapath.aspx
Just check whether the db is in that path -if not copy it there- and use it there...
Other locations could be ApplicationData/CommonApplicationData/LocalApplicationData from http://msdn.microsoft.com/de-de/library/14tx8hby.aspx and http://msdn.microsoft.com/de-de/library/system.environment.specialfolder.aspx
所有文件都正确复制。
我尝试使用
Application.ExecutablePath
而不是Path.GetFullPath(".")
它工作得很好...
All the files are copying correctly..
I tried with
Application.ExecutablePath
instead ofPath.GetFullPath(".")
it work's great...