NHibernate连接字符串问题

时间:2011-01-09 22:27:07

标签: c# .net nhibernate oracle10g

我正在使用NHibernate和Web应用程序以及Oracle 10g XE,我目前收到以下错误:

ORA-06413: Connection not open.

我的猜测是我的连接字符串有问题。这是我在Web.config中的Hibernate配置:

<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>
      <mapping assembly="Domain" />
    </session-factory>
</hibernate-configuration>

我也尝试使用以下连接字符串:

<property name="connection.connection_string">
  User ID=myid;Password=mypassword;Data Source=localhost
</property>

导致以下错误:

ORA-12154: TNS:could not resolve the connect identifier specified.

任何人都可以提供任何有关我可能在这里做错的见解吗?

修改

我在同一个解决方案中创建了一个控制台应用程序项目。我创建了一个具有相同设置的hibernate.cfg.xml文件,并将其添加到该项目中。我可以毫无问题地坚持对象。

我已将我的数据库从Oracle 10g切换到MySQL,它在Web应用程序中运行良好。为什么Oracle 10g只能在控制台应用程序中工作,而不能在Web应用程序中工作?

2 个答案:

答案 0 :(得分:1)

显然,Oracle 10g在64位系统上有点挑剔。最好的选择似乎是转向MySQL。

答案 1 :(得分:0)

我今天遇到了这个错误并发现了有趣的事情。 我试图在语句

之前使用XE客户端oracle.dataaccecc.dll作为参考
 sessionFactory = new NHibernate.Cfg.Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate\\Oracle.cfg.xml")).BuildSessionFactory();
            
我输入了这些内容:

OracleConnection conn = new OracleConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
            conn.Open();
conn.Close();

一切都开始奏效了。