Is SqlPersister supposed to create the database



Just wondering whether the database itself is supposed to be created automatically when running endpoint with SqlPersistance setup. Looking at the auto generated sql scripts they are only handling creation of tables, and looking at the example code, you have actually added a method explicitly (EnsureDatabaseExists()) that handles db creation part (for me this is an indication that db creation is something we have to take care of our selves)

My setup is pretty default, following the doco:

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointSqlServer");
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var connection = @"Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True";
    connectionBuilder: () =>
        return new SqlConnection(connection);
var subscriptions = persistence.SubscriptionSettings();

(Szymon Pobiega) #2


The SqlPersistence installers don’t create the database. They expect that the database already exists. This is why EnsureDatabaseExists method exist in the samples. We want to ensure that the samples are as easy to run as possible. Making DB creation automatic removes one thing from the TODO list for the user when running the sample.

When in real, production environment, the creation of the database is usually handled by a process separate to actually installing and running the endpoint. This is why the decision was to not include it in the installers.