部署带有嵌入式sqlite的winform应用程序
我正在部署一个使用 vs 2008 0n XP sp3 构建的 winform 应用程序。
我创建了一个带有空架构的数据库,将其放入项目的根文件夹中,并在属性中选择了构建操作
:嵌入式资源和复制到输出目录< /code> :始终复制。现在,我不再在 app.config 连接字符串部分中添加连接字符串,而是在
appSetting
中添加一个条目:key
="database";value
=" mydb.db;版本=3”。
因此,为了创建我的 connectionString
我使用:
SQLiteConnection con = new SQLiteConnection("Data Source=" + Path.Combine(Application.StartupPath, ConfigurationManager.AppSettings["database"]));
一切正常,我将应用程序与安装项目打包在一起。现在,在我安装应用程序后,找不到数据库,我不得不将数据库复制到安装项目中的应用程序文件夹
使其正常工作。
我的想法是,由于始终复制
,数据库应该位于应用程序DLL中。但我无法访问它。那么我到底做错了什么?
我怀疑我应该刚刚连接到根数据库,这意味着不使用 Application.StartupPath
但我在这里询问最佳实践,因为我所做的工作正在工作,但仍然看起来像解决方法,所以请可以有人与我分享他的经验吗? 感谢您的阅读
I'm deploying a winform application built with vs 2008 0n XP sp3.
I created a database with empty schema which i dropped in the root folder of the project and in properties i choosed Build Action
: Embedded Resources and Copy to Output directory
: Copy always. Now instead of having connectionstring in the app.config connectionString section, i put an entry in appSetting
: key
="database";value
="mydb.db;Version=3".
So to create my connectionString
i used :
SQLiteConnection con = new SQLiteConnection("Data Source=" + Path.Combine(Application.StartupPath, ConfigurationManager.AppSettings["database"]));
Everything works fine and i packaged the app with a setup project.Now after i installed the app the database could not be found and i was obliged to copy the database to the Application Folder
in the setup project for it to work.
what i thought is that db is supposed to be in the app dll because of copy always
.but i can't access it.So what exactly did i do wrong?
i'm suspecting i should have just connected to the root db meaning not using Application.StartupPath
But i'm here asking for the best practices cause what i did is working but still looking like workaround so please can anyone share his experience with me?
thanks for reading
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Embedded Resource
意味着数据库嵌入到您的 dll 中。复制到输出目录
设置在这种情况下不适用,该设置用于构建操作:内容
。嵌入数据库后,您基本上必须在第一次使用时取消嵌入它。为此,请从程序集中读取它并将其存储到文件中。
Embedded Resource
means the database gets embedded in your dll. TheCopy to output directory
setting doesn't apply in this case, that's used forBuild Action: Content
.With the database embedded, you basically have to un-embed it on first use. To do this read it out of the Assembly and store it to a file.