[英]How to set a relative path to a SQL Server Compact database?
How do I write the path to a compact database so it will work for everyone working on the project? 如何编写压缩数据库的路径,以便它适用于项目的每个人?
My local path looks something like this: 我的本地路径看起来像这样:
SqlCeConnection con =
new SqlCeConnection(@"Data Source=C:\Users\Name\Documents\Visual Studio 2012\Projects\Unwanted\Local\Path\App_Data\Databas.sdf");
I think I've seen people use "~" sign to do stuff like this, anyhow I want to make this connection viable for everyone no matter how their mapping looks like. 我想我已经看到人们使用“〜”符号做这样的事情,无论如何我想让这个连接对所有人都可行,无论他们的映射如何。
Hope I made myself clear! 希望我清楚自己! :)
:)
The tilde ( ~
) is used in ASP.NET to denote the root of the web site - it cannot however be used in a SQL Server CE connection string. 代码(
~
)在ASP.NET中用于表示网站的根目录 - 但它不能用于SQL Server CE连接字符串。
You can try to just use 你可以尝试使用
SqlCeConnection con =
new SqlCeConnection(@"Data Source=App_Data\Database.sdf");
Then the .NET app will look into the current directory (from where it's been started - often the (project dir)\\bin\\debug
folder) for a App_Data
folder and for a Database.sdf
file inside that folder. 然后,.NET应用程序将查看当前目录(从哪里开始 - 通常是
(project dir)\\bin\\debug
文件夹),用于App_Data
文件夹和该文件夹中的Database.sdf
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.