使用 System.Data.SQLite 如何使用相对路径在连接字符串中指定数据库文件
想要将我的项目部署在不同的服务器上,我希望能够使用相对路径指定连接字符串。 我似乎无法让它发挥作用,想知道是否有一些技巧......?
Wanting to deploy my project on different servers I would prefer to be able to specify a connect string using a relative path. I can't seem to get that to work and want to know if there is some trick to it...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
建议
您可以在应用程序中构建绝对路径并将其传递到连接字符串中。
因此,如果您知道数据库文件位于应用程序文件夹的
database
子文件夹中,您可以执行以下操作 (C#):(有人可能可以纠正我如何获取当前路径) 。
A suggestion
You could build the absolute path in the app and pass that in the connection string.
So, if you know that the database file is in the
database
subfolder of the application folder, you could do something like this (C#):(Someone can probably correct me on how to get the current path).
这个怎么样?
我相信
|DataDirectory|
指向您的应用程序所在的目录。 我使用 NHibernate,它适用于以下内容:How about this?
I believe
|DataDirectory|
point to the directory where your app is located. I use NHibernate and it works with the following:像这样:
String currentPath = System.IO.Path.GetDirectoryName( Application.ExecutablePath );
Like this:
String currentPath = System.IO.Path.GetDirectoryName( Application.ExecutablePath );