Trying to create a database schema - There was no DB provider available, unable to create connection
I started with the Northwind spring.net/NHibernate example. I am trying to get the existing example to generate a schema. I altered the CustomerEditController web.xml entry to
<object name="CustomerEditController" type="NHibernateCustomerEditController" scope="session">
<constructor-arg name="sessionFactory" ref="NHibernateSessionFactory"/>
<constructor-arg name="local" ref="&NHibernateSessionFactory"/>
</object>`
Changed the NHibernateCustomerEditController
to 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 that leads to the MakeANewDatabase
method.
When I hit the button i receive the error There was no DB provider available, unable to create connection
. It looks like when the SchemaExport
is being created the DBProvider
is 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 exce开发者_运维问答ption 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
It looks like the config pulled from the local session factory is not fully populated, Solved the issue by using spring methods.
public void MakeANewDatabase()
{
LocalsessionFactory.CreateDatabaseSchema();
}
精彩评论