We’re in the middle of upgrading an old application (NSB 3.3) which used nHibernate based saga and timeout persistence.
Under NSB 3.3 you setup the persistence for these in independent sections of the app.config, and we chose to put the timeout related stuff in a “timeout” schema, and the saga related stuff in a “saga” schema in the SQL Server database.
We’re now trying to migrate the old application to NSB 5/ NSB.NHibernate version 6.2.10 and it does not appear that there is a way to configure a DIFFERENT schema for timeouts vs. sagas. Using the “code based” initialization as shown below STILL causes the timeout tables to be created in the “saga” schema, it appears that the last configuration of the “default_schema” pollutes all the other ones.
When the endpoint starts it errors out because it can’t query the “saga.TimeoutEntity” table.
Here’s the initialization code:
configuration.EnableFeature<Sagas>();
var timeoutConfig = new Configuration
{
Properties =
{
["dialect"] = "NHibernate.Dialect.MsSql2012Dialect",
["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider",
["default_schema"] = "timeout",
[NHibernate.Cfg.Environment.ConnectionStringName] = "NServiceBus/Persistence"
}
};
var timeouts = configuration.UsePersistence<NHibernatePersistence, StorageType.Timeouts>();
timeouts.UseConfiguration(timeoutConfig);
timeouts.DisableSchemaUpdate();
var sagaConfig = new Configuration
{
Properties =
{
["dialect"] = "NHibernate.Dialect.MsSql2012Dialect",
["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider",
["default_schema"] = "saga",
[NHibernate.Cfg.Environment.ConnectionStringName] = "NServiceBus/Persistence"
}
};
var sagas = configuration.UsePersistence<NHibernatePersistence, StorageType.Sagas>();
sagas.UseConfiguration(sagaConfig);
sagas.DisableSchemaUpdate();
and here’s the error:
2018-07-02 11:50:32,566 [13] ERROR NHibernate.AdoNet.AbstractBatcher - Could not execute query: SELECT this_.Id as y0_, this_.Time as y1_ FROM saga.TimeoutEntity this_ WHERE this_.Endpoint = @p0 and (this_.Time > @p1 and this_.Time <= @p2) ORDER BY this_.Time asc
System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'saga.TimeoutEntity'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)