简体   繁体   English

Nhibernate 2.1和mysql 5-安装时InvalidCastException

[英]Nhibernate 2.1 and mysql 5 - InvalidCastException on Setup

I am trying to use NHibernate with Spring.Net und mySQL 5. However, when setting up the connection and creating the SessionFactoryObject, I get this InvalidCastException: 我正在尝试将NHibernate与Spring.Net和mySQL 5一起使用。但是,在建立连接并创建SessionFactoryObject时,出现此InvalidCastException异常:

NHibernate seems to cast MySql.Data.MySqlClient.MySqlConnection to System.Data.Common.DbConnection which causes the exception. NHibernate似乎将MySql.Data.MySqlClient.MySqlConnection转换为导致异常的System.Data.Common.DbConnection。

System.InvalidCastException wurde nicht behandelt.
  Message="Das Objekt des Typs \"MySql.Data.MySqlClient.MySqlConnection\" kann nicht in Typ \"System.Data.Common.DbConnection\" umgewandelt werden."
  Source="NHibernate"
  StackTrace:
       bei NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() in c:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SuppliedConnectionProviderConnectionHelper.cs:Zeile 25.
       bei NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) in c:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs:Zeile 43.
       bei NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) in c:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs:Zeile 17.
       bei NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in c:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:Zeile 169.
       bei NHibernate.Cfg.Configuration.BuildSessionFactory() in c:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:Zeile 1090.
       bei OrmTest.Program.Main(String[] args) in C:\Users\Max\Documents\Visual Studio 2008\Projects\OrmTest\OrmTest\Program.cs:Zeile 24.
       bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException:

I am using the programmatically setup approach in order to get a quick NHibernate Setup. 我正在使用以编程方式进行安装的方法,以便快速进行NHibernate安装。 Here is the setup Code: 这是设置代码:

Configuration config = new Configuration();
            Dictionary props = new Dictionary();
            props.Add("dialect", "NHibernate.Dialect.MySQL5Dialect");
            props.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
            props.Add("connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
            props.Add("connection.connection_string", "Server=localhost;Database=orm_test;User ID=root;Password=password");
            props.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring");
            config.AddProperties(props);
            config.AddFile("Person.hbm.xml");
            ISessionFactory factory = config.BuildSessionFactory();
            ISession session = factory.OpenSession();

Is something missing? 缺少什么吗? I downloaded the current mysql Connector from the mysql Website. 我从mysql网站下载了当前的mysql连接器。

Shame on me, I downloaded accidently a wrong mysql connector and not the latest version: http://dev.mysql.com/downloads/connector/net/6.0.html 真可惜,我意外地下载了错误的mysql连接器,而不是最新版本: http : //dev.mysql.com/downloads/connector/net/6.0.html

Sorry! 抱歉!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM