How to set a relative path to a SQL Server Compact database?

对着背影说爱祢 提交于 2019-12-08 04:32:35

问题


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! :)


回答1:


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.

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.



来源:https://stackoverflow.com/questions/12932963/how-to-set-a-relative-path-to-a-sql-server-compact-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!