5

I want to generate a database script without having an actual database connection string declared.

To do this for now i use NHibernate ExportSchema bases on a NHibernate configuration generated with Fluent NHibernate this way (during my ISessionFactory creation method):

FluentConfiguration configuration = Fluently.Configure();               
//Mapping conf ...
configuration.Database(fluentDatabaseProvider);
this.nhibernateConfiguration = configuration.BuildConfiguration();
returnSF = configuration.BuildSessionFactory();     

//Later
new SchemaExport(this.nhibernateConfiguration)              
                .SetOutputFile(filePath)
                .Execute(false, false, false);      

fluentDatabaseProvider is a FluentNHibernate IPersistenceConfigurer which is needed to get proper sql dialect for database creation.

When factory is created with an existing database, everything works fine. But what i want to do is to create an NHibernate Configuration object on a selected database engine without a real database behind the scene... And i don't manage to do this.

If anybody has some idea.

1
  • Did you find an answer to this? I have the same requirement. Commented Apr 6, 2011 at 20:22

2 Answers 2

1

This is what I used. My mistake was calling BuildSessionFactory which tries to connect to the database:

        var config = Fluently.Configure()
          .Database(MsSqlConfiguration.MsSql2008)
          .Mappings(m =>
            m.FluentMappings.AddFromAssemblyOf<SessionManager>());

        new SchemaExport(config.BuildConfiguration())
                .SetOutputFile(filedestination)
                .Create(false, false);
Sign up to request clarification or add additional context in comments.

Comments

0

Try using:

.Create(false, false);

inplace of

.Execute(false, false, false); 

Do not add the connectionstring property to the IPersistenceConfigurer (fluentDatabaseProvider).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.