How can I prever Fluently.Configure connection to the DB automatically?
Our setup is detailed below.
We have the following static method to create a session factory:
public static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
IfxOdbcConfiguration
.Informix
.ConnectionString("DSN=ODBCCONNECTION")
.Driver<CompanyCore.Nhibernate.Core.ProfiledODBCClientDriver>()
.Dialect<InformixDialect1000>()
.ShowSql()
)
.Mappings(
m => m.FluentMappings.AddFromAssemblyOf<Task>()
)
.BuildSessionFactory();
}
Which is used with our IOC setup to create the SessionFactory, however, due to what is required by our DB team, each user must open his/her own connections as their user (Using impersonalisation) - to allow for process identification, to see who is running what on the Informix server.
To create the individual connections we use:
public static ISession GetMySession(ISessionFactory factory, string user)
{
CompanyCore.Nhibernate.Core.ProfiledODBCClientDriver drv = new Enact.Nhibernate.Core.ProfiledODBCClientDriver();
drv.Configure(new Dictionary<string, string>());
string conn = "DSN=ODBCCONNECTION";
IDbConnection db = drv.CreateConnection();
db.ConnectionString = conn;
db.Open();
return factory.OpenSession(db);
}
These connections are closed when our UOW calls dispose.
We call CreateSessionFactory() on APP Start and then pass this factory around with IOC, but at this point there is no impersonalisation user, and thus causes a app error on first load.
We have thought about using a standard user which has access for things like first load, but surely there is a better way?
You need to disable the automatic-keyword-quoting: configuration.SetProperty(Environment.Hbm2ddlKeyWords, "none")
See this post on "Prevent NHibernate to connect to the database on configuration.BuildSessionFactory()" for more details: https://groups.google.com/forum/?fromgroups=#!topic/nhusers/F8IxCgYN038
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With