-
Dear NHibernate devs, Motivation came from Nerdhold blog post where you can extend the internal class MyCustomConnectionProvider : DriverConnectionProvider
{
protected override string ConnectionString
{
get => Manager.Instance.GetConfiguration().DatabaseConnectionString;
}
public override DbConnection GetConnection()
{
try
{
return base.GetConnection();
}
catch (Exception ex)
{
var id = Manager.Instance.GetConfiguration().Name;
throw new ArgumentException($"Can't connect to database {id}");
}
}
public override async Task<DbConnection> GetConnectionAsync(CancellationToken cancellationToken)
{
try
{
return await base.GetConnectionAsync(cancellationToken);
}
catch (Exception ex)
{
var id = Manager.Instance.GetConfiguration().Name;
throw new ArgumentException($"Can't connect to database {id}");
}
}
} Challenges
db.ConnectionString = settings.DefaultSqlConnection;
notes: Questions
Server=.\SQLEXPRESS;Database=master;Trusted_Connection=Yes;
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Having just read the start of the blog you have linked, I think that this blog is unsuitable for most cases. Switching to connection release mode "on close" is bad for connections reuse and will increase the number of connection simultaneously opened on your database, which could cause serious issues. Your question is unclear, but it seems to me you search a solution for shardings with NHibernate without creating a session factory for each shard. Maybe Nhibernate.Shards does that, I do not know. @ggeurts, you seem to be contributor of it, may you know? |
Beta Was this translation helpful? Give feedback.
-
If the idea is to represent the same schema, for different setups, you can use the built in MultiTenancy support. It can be used for purposes which has nothing to do with multitenancy. |
Beta Was this translation helpful? Give feedback.
-
Hello,
NHibernate.Shards reuses configuration but keeps a session factory per
shard. That was sufficient for my purpose at the time.
Kind Regards,
Gerke.
…On Mon, 23 May 2022, 21:06 Frédéric Delaporte, ***@***.***> wrote:
Having just read the start of the blog you have linked, I think that this
blog is unsuitable for most cases. Switching to connection release mode "on
close" is bad for connections reuse and will increase the number of
connection simultaneously opened on your database, which could cause
serious issues.
Your question is unclear, but it seems to me you seek a solution for
shardings with NHibernate without creating a session factory for each
shard. Maybe Nhibernate.Shards
<https://www.nuget.org/packages/NHibernate.Shards> does that, I do not
know. @ggeurts <https://github.com/ggeurts>, you seem to be contributor
of it, may you know?
—
Reply to this email directly, view it on GitHub
<#3068 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFHG7MQJQFQQDCZSICWDATVLPJM7ANCNFSM5WWZJC7A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
If the idea is to represent the same schema, for different setups, you can use the built in MultiTenancy support. It can be used for purposes which has nothing to do with multitenancy.