Open async DB connection

60 views
Skip to first unread message

satish viswanath

unread,
Dec 3, 2019, 11:31:59 AM12/3/19
to Fluent NHibernate


I'm using Fluent NHibernate and using a connection provider in my configuration.

return Fluently.Configure()
                .Database(


                    PostgreSQLConfiguration.PostgreSQL82.Provider<TenantConnectionProvider>()
                )
                
                .Mappings(cfg =>
                {
                    cfg.FluentMappings.AddFromAssemblyOf<NHibernateSessionSource>();
                })
                .ExposeConfiguration(
                    c => {
                        c.DataBaseIntegration(prop =>
                        {
                            prop.BatchSize = 20;
                        });
                        c.SetProperty(NHibernate.Cfg.Environment.SessionFactoryName, name);
                        c.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true");

                    })
                .Diagnostics(x => x.Enable(true))
                .BuildConfiguration();
public class TenantConnectionProvider : DriverConnectionProvider
{
public override async Task<DbConnection> GetConnectionAsync(CancellationToken cancellation = default)
        {
// open connection async
}
public override DbConnection GetConnection()
        {
// open connection sync
}
}

I'm facing the following issues.


1.  NHibernate doesn't open the connection async using GetConnectionAsync() instead the connection is always open sync using the method GetConnection()
2. For each query that is executed a new connection is being opened. Can we use a single db connection per session?





Gleb Chermennov

unread,
Dec 4, 2019, 9:28:00 AM12/4/19
to Fluent NHibernate
Hello satish.
Looks like your issues have nothing to do with Fluent NHibernate.
I think your questions would be answered faster if asked on NHibernate mailing list. 

Regarding your second question - if you're dealing with Postgresql, you need to take connection pooling into consideration. Npgsql has it built-in (which only works fine if you have one instance of your app), however if you're using PgBouncer you'd likely want to turn it off 
Reply all
Reply to author
Forward
0 new messages