开发者

NHibernate connection problem

开发者 https://www.devze.com 2023-01-16 11:58 出处:网络
I am using sql server 2005 but having error message on _sessionFactory = configuration.BuildSessionFactory();

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:


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.


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> 


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消