How to stop Fluently.Configure connect automatically

How can I pre-launch a Fluently.Configure DB connection automatically?

Our setup is detailed below.

We have the following static method to create a factory session:

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 our DB team requires, each user has to open their own connections as their user (using impersonation) - to provide process identification to find out who is running on Informix server.

To create separate 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 are removed.

We call CreateSessionFactory()

in APP Start and then pass this factory using IOC, but at the moment there is no impersonal user and hence throws an application error on first boot.

We thought about using a standard user who has access to things like first boot, but surely there is a better way?

+3


source to share


1 answer


You need to disable automatic keyword-quoting: configuration.SetProperty (Environment.Hbm2ddlKeyWords, "none")



See this post under "Prevent NHibernate from connecting to the database by config .BuildSessionFactory ()" for more information: https://groups.google.com/forum/?fromgroups=#!topic/nhusers/F8IxCgYN038

+5


source







All Articles