Trying to create a database schema - there were no database providers, failed to create a connection

I started with the Northwind example spring.net/NHibernate. I am trying to get an existing example for creating a schema. I changed the entry CustomerEditController web.xml to

<object name="CustomerEditController" type="NHibernateCustomerEditController" scope="session">
  <constructor-arg name="sessionFactory" ref="NHibernateSessionFactory"/>
  <constructor-arg name="local" ref="&amp;NHibernateSessionFactory"/>
</object>`

Changed NHibernateCustomerEditControllerto the following:

public class NHibernateCustomerEditController : ICustomerEditController
{
    private readonly ISessionFactory sessionFactory;
    private readonly LocalSessionFactoryObject LocalsessionFactory;
    private Customer currentCustomer;

    public NHibernateCustomerEditController(ISessionFactory sessionFactory, LocalSessionFactoryObject local)
    {
        this.sessionFactory = sessionFactory;
        this.LocalsessionFactory = local;
    }

    private ISession Session
    {
        get { return sessionFactory.GetCurrentSession(); }
    }

    public void EditCustomer(Customer customer)
    {
        currentCustomer = customer;
    }

    public void Clear()
    {
        currentCustomer = null;
    }

    public Customer CurrentCustomer
    {
        get
        {
            Customer customer = currentCustomer;

            //since the Customer entity may have been retrieved from a prior request, we need to reattach it to the current session
            // in order to support lazy-loading, etc. on the Customer
            Session.Lock(customer, LockMode.None);

            return customer;
        }
    }
    public void MakeANewDatabase() {
        SchemaExport schema = new SchemaExport(LocalsessionFactory.Configuration);
        schema.Create(true, true);
    }

}

I added a button to the customer list page, which leads to the method MakeANewDatabase.

When I click the button, I get an error message There was no DB provider available, unable to create connection. It appears that when created, the SchemaExportvalue DBProvideris null.

Full error text:

An exception of type 'System.Exception' occurred in Spring.Data.NHibernate30.DLL but was not handled in user code

Additional information: There was no DB provider available, unable to create connection

An exception of type 'NHibernate.HibernateException' occurred in NHibernate.DLL but was not handled in user code

Additional information: There was no DB provider available, unable to create connection
+3
source share
1 answer

It seems that the configuration extracted from the local factory session is not completely populated, solved the problem using the spring methods.

public void MakeANewDatabase()
{ 
  LocalsessionFactory.CreateDatabaseSchema(); 
}
+3

All Articles