1

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jlodenius
  • 829
  • 2
  • 13
  • 24

1 Answers1

4

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hmm, this method seemed to work but it doesen't, dont you need an absolute path for an SqlCE connection? – jlodenius Oct 17 '12 at 15:53
  • [According to this web site](http://www.connectionstrings.com/sql-server-2005-ce) - no, doesn't seem to be a requirement. Relative paths should work just fine ... – marc_s Oct 17 '12 at 15:55