views:

172

answers:

2

Hi all,

I have the following nhibernate cfg file:

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">Data Source=dbFile.db;Version=3</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>

However this creates and references dbFile.db in the bin/Debug folder. I was wondering if there is any way to refernce another folder i.e. something like .../app/database/dbFile.db?

Thanks in advance

+1  A: 

You can set the connection string property from c# code. You have to do this before you call the Configure() method.

var configuration = new Configuration();
config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, myCustomDbPath);
configuration.Configure();

Hope that helps.

Amith George
Note that `myCustomDbPath` should be the full connection string. Not just `dbFile.db`, but `Data Source=dbFile.db;Version=3`.
Matthew
A: 

Maybe you can use DataDirectory-Property to start from the Exe-Path:

Data Source=|DataDirectory|../app/database/dbFile.db;Version=3

or

Data Source=jdbc:sqlite:../app/database/path.db;Version=3

Edit: After some googling i found out that this probably won't work. if not i would go with striders solution setting the property at runtime.

zoidbeck