Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:40+00:00 2026-05-27T17:30:40+00:00

I have several NServiceBus Generic Host based windows services installed on the same server

  • 0

I have several NServiceBus Generic Host based windows services installed on the same server as the SQL Server instance that contains my subscription storage database. When the server boots my NServiceBus Host services try to access the subscription storage database before SQL Server is up.

Here’s what I’ve tried so far:

  1. Added a windows server dependency on MSSQLSERVER. This did not solve the problem.
  2. Added a 1 minute sleep in IWantCustomInitialization.Init to verify the cause of the problem described above. This solved the problem but it’s a very crude solution.

What is the recommended way to handle this problem?

For reference find my DBSubscriptionStorageConfig and the exception that occurs when my windows services try to start below.

<DBSubscriptionStorageConfig>
<NHibernateProperties>
  <add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/>
  <add Key="connection.driver_class" Value="NHibernate.Driver.SqlClientDriver"/>
  <add Key="connection.connection_string" Value="Data Source=.;Initial  Catalog=NServiceBus;Integrated Security=SSPI"/>
  <add Key="dialect" Value="NHibernate.Dialect.MsSql2008Dialect"/>  
</NHibernateProperties>
</DBSubscriptionStorageConfig>


ERROR NHibernate.Tool.hbm2ddl.SchemaUpdate [(null)] <(null)> - could not get database metadata
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "NServiceBus" requested by the login. The login failed.
Login failed for user 'SE1\fooservice'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler,            
SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,     
TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,         
SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options,       
Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,       
DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection()
at NHibernate.Tool.hbm2ddl.ManagedProviderConnectionHelper.Prepare()
at NHibernate.Tool.hbm2ddl.SchemaUpdate.Execute(Action`1 scriptAction, Boolean doUpdate)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:30:40+00:00Added an answer on May 27, 2026 at 5:30 pm

    I ended up creating a class which implements IWantCustomInitialization to prevent my windows services from starting before they can connect to the database. The class should probably have some logging code added but it solves my problem for now.

    Here’s the code.

    public class DbDependencyChecker : IWantCustomInitialization
    {
        private const int ConnectionRetries = 15;
        private const int TimeBetweenRetries = 60000;      
        private const string DefaultConnectionName = "DbDependency";
        private const string CustomConnectionNameKey = "DbDependencyConnectionName";
    
        public void Init()
        {
            var connectionName = ConfigurationManager.AppSettings[CustomConnectionNameKey];
            if (string.IsNullOrWhiteSpace(connectionName))
                connectionName = DefaultConnectionName;
            var providerName = ConfigurationManager.ConnectionStrings[connectionName].ProviderName;
            var connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
    
            if (string.IsNullOrWhiteSpace(providerName) || string.IsNullOrWhiteSpace(connectionString))
                return;
    
            for (var i = 0; i < ConnectionRetries; i++)
            {
                if (TryToConnect(providerName, connectionString))
                    break;
                System.Threading.Thread.Sleep(TimeBetweenRetries);
            }
        }
    
        private static bool TryToConnect(string providerName, string connectionString)
        {
            try
            {
                using (var connection = CreateConnection(providerName, connectionString))
                {
                    connection.Open();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    
        private static IDbConnection CreateConnection(string providerName, string connectionString)
        {
            var provider = DbProviderFactories.GetFactory(providerName);
            var connection = provider.CreateConnection();
            connection.ConnectionString = connectionString;
            return connection;
        }        
    }
    

    The config file would look like this:

    <connectionStrings>
      <add name="SomeDb" providerName="System.Data.SqlClient" connectionString="connection string" />
    </connectionStrings>
    
    <appSettings>
      <add key="DbDependencyConnectionName" value="SomeDb"/>
    </appSettings>
    

    Or like this:

    <connectionStrings>
      <add name="DbDependency" providerName="System.Data.SqlClient" connectionString="connection string"/>    
    </connectionStrings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server with several instances of the NServiceBus Generic Host installed as
We have several jobs that run concurrently that have to use the same config
We have several reports that do the same formatting operations (e.g. displaying PASS or
I have several LINQ queries that will churn records (up to a million) based
A suite of integration services that use NServiceBus have been dropped in my lap
I have a Windows service that monitors several mailboxes for new mail. Once new
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
I have several old 3.5in floppy disks that I would like to backup. My
I have several applications that are part of a suite of tools that various
We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.