c#nHibernate与Postgres数据库连接字符串

时间:2015-04-14 02:39:43

标签: c# postgresql nhibernate

我在c#解决方案中使用NHibernate作为数据访问层(DAL)。注意,我在许多情况下成功使用了Hibernate和NHibernate,但这是第一次使用Postgres DB。下面是我的NHibernate配置XML文件和关联的sessionBuilder。我收到以下错误,这是在BuildSessionFactory()方法调用中引发的。我尝试了一百种连接字符串,无济于事。我在这里错了哪些想法?

[ArgumentException: key=value argument incorrect in ConnectionString 
Parameter name: data source]

这是XML配置:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
        <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
        <property name="connection.connection_string_name">server=1.1.1.1;port=8060;database=workgroup;user id=tab;password=***;</property>
<property name="current_session_context_class">web</property>
<mapping assembly="ClientAnalyticsDashboard"/>
</session-factory>
</hibernate-configuration>

这是代码(在显示的最后一行出现错误):

Configuration configuration = new Configuration();
configuration.AddAssembly(Assembly.GetCallingAssembly());
configuration.Proxy(p => { p.Validation = false; });
TabSessionFactory = configuration.BuildSessionFactory();

1 个答案:

答案 0 :(得分:1)

我认为您需要将connection.connection_string_name更改为connection.connection_string