NHibernate connection string problem
I'm using NHibernate with a web application and Oracle 10g XE, and I'm currently getting the following error:
ORA-06413: Connection not open.
My guess is it's a problem with my connection string. Here's my Hibernate configuration in Web.config:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="MyProject.MyAssembly">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)));User ID=myid;Password=mypassword</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<map开发者_StackOverflow社区ping assembly="Domain" />
</session-factory>
</hibernate-configuration>
I've also tried using the following connection string:
<property name="connection.connection_string">
User ID=myid;Password=mypassword;Data Source=localhost
</property>
That resulted in the following error:
ORA-12154: TNS:could not resolve the connect identifier specified.
Could anyone provide any insight into what I might be doing wrong here?
Edit
I created a console application project inside the same solution. I created a hibernate.cfg.xml file with the same settings and added it to that project. I can persist objects with no problems.
I've switched my database from Oracle 10g to MySQL and it works fine in the web application. Why does Oracle 10g only work in the console application and not in the web application?
Apparently Oracle 10g is a bit finicky on 64-bit systems. The best option seemed to be switching to MySQL.
I faced this error today and found interesting thing. I tried to use XE client oracle.dataaccecc.dll as reference and before the statement
sessionFactory = new NHibernate.Cfg.Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate\\Oracle.cfg.xml")).BuildSessionFactory();
i entered these lines:
OracleConnection conn = new OracleConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connString"].ConnectionString); conn.Open(); conn.Close();
And everything started to work.
精彩评论