Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relative path for database file in config file

I've created a WCF REST service that uses nhibernate to connect to sql server compact edition database. Hence I configure the NHibernate datasource like:

<property name="connection.connection_string">Data Source=[Path]\MyDb.sdf</property>

The annoyance I'm running into now is that I can't figure out how to avoid having to write out the absolute path in the config. This is annoying since I keep the database file as part of the project in the App_Data folder. So I shouldn't have to update the path e.g. when I deploy the project to another location, even if the absolute path is different.

Using procmon I noticed that if I don't write an absolute pat in the Data Source config, it is interpreted as relative to the path: *C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0*.

Is it possible have nhibernate assume we want to relate the path to the application bin folder instead (which is where my App_Data/MyDb.sdf ends up)?

like image 897
Manolo Avatar asked Jun 09 '11 15:06

Manolo


Video Answer


1 Answers

You should use:

Data Source=|DataDirectory|\MyDb.sdf

|DataDirectory| points to the App_Data folder.

like image 164
Diego Mijelshon Avatar answered Nov 08 '22 20:11

Diego Mijelshon