views:

22

answers:

3

I am using sql server 2005

but having error message on _sessionFactory = configuration.BuildSessionFactory();

What is wrong and how can I correct it?


My Hibernate.cfg.xml

 <property name="connection.driver_class">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<!--<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>-->
<property name="connection.connection_string">Server=localhost\SQLServer2005;database=NHibernate101;Integrated Security=True;</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="Infrastructure"></mapping>

and my in my web.config

    <connectionStrings>
    <add name="ApplicationServices" connectionString="Server=localhost\SQLServer2005;database=NHibernate101;" providerName="NHibernate.Connection.DriverConnectionProvider"/>
</connectionStrings>

Error message is:

NHibernate.HibernateException was unhandled by user code Message=Could not create the driver from NHibernate.Connection.DriverConnectionProvider. Source=NHibernate StackTrace: at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings) at NHibernate.Connection.ConnectionProvider.Configure(IDictionary2 settings) at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary2 settings) at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary2 properties) at NHibernate.Cfg.Configuration.BuildSettings() at NHibernate.Cfg.Configuration.BuildSessionFactory() at Core.Domain.Repositories.NHibernateHelper.get_SessionFactory() in C:\Documents and Settings\nHibernate101\NHibernate101 Final\NHibernate101\Core\Domain\Repositories\NHibernateHelper.cs:line 22 at Core.Domain.Repositories.NHibernateHelper.OpenSession() in C:\Documents and Settings\nHibernate101\NHibernate101 Final\NHibernate101\Core\Domain\Repositories\NHibernateHelper.cs:line 30 at Core.Domain.Repositories.PostRepository.Core.IRepository.GetAll() in C:\Documents and Settings\nHibernate101\NHibernate101 Final\NHibernate101\Core\Domain\Repositories\PostRepository.cs:line 59 at NHibernate101.Controllers.PostsController.Index() in C:\Documents and Settings\nHibernate101\NHibernate101 Final\NHibernate101\NHibernate101\Controllers\PostsController.cs:line 22 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c_DisplayClassd.b_a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) InnerException: System.InvalidCastException Message=Unable to cast object of type 'NHibernate.Connection.DriverConnectionProvider' to type 'NHibernate.Driver.IDriver'. Source=NHibernate StackTrace: at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings) InnerException:

+1  A: 

Your configuration is incorrect. Use this one:

<property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
<property name="hibernate.connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property> 
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property> 
<property name="connection.connection_string">Server=localhost\SQLServer2005;database=NHibernate101;Integrated Security=True;</property> 
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
<mapping assembly="Infrastructure"></mapping> 
Pierre 303
Sorry this does not help either
I`m having the error message: [InvalidCastException: Unable to cast object of type 'NHibernate.Connection.DriverConnectionProvider' to type 'NHibernate.Driver.IDriver'.] NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) +194
It's because you mixed the Connection Provider and the Connection Driver Class in your configuration.
Pierre 303
A: 

Could it be the fact that you've specified the SQL2000 dialect rather than the 2005 one? I've never had that happen so I'm not sure if it would raise this error.

kprobst
A: 

You're receiving that error because in your Hibernate.cfg.xml you're telling NHibernate to use the NHibernate.Connection.DriverConnectionProvider class for connection.driver_class property. The connection.driver_class property is expecting an IDriver interface while the NHibernate.Connection.DriverConnectionProvider is not.

Brian
What should be the driver name?
NHibernate.Driver.SqlClientDriver
Brian