我正在用 NHibernate 2.1 替换旧的 DAL。我的 NHibernate 配置适用于我的本地开发机器,但不适用于 UAT。 UAT 数据库是在非默认端口上设置的集群。我正在使用类似于下面的标准 NHibernate confie 文件:
<?xml version="1.0" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=(local);Initial Catalog=dbname;User Id=user;Password=********</property>
</session-factory>
</hibernate-configuration>
我认为问题在于我在 NHibernate 配置文件中指定连接字符串的方式,因为我现有的 DAL 使用以下连接字符串:
Data Source=uatserver\db01,1433;
Initial Catalog=dbname;
User ID=dbuser;
Password=userpassword
在 NHibernate 配置文件中,我尝试了以下组合,但没有任何效果,并且我收到了不同的错误消息,但大多数都说无法连接。
<property name="connection.connection_string">
Server=tcp:(uatserver\db01),1433;
Initial Catalog=dbname;
User ID=dbuser;
Password=userpassword</property>
错误:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:TCP 提供者,错误:0 - 不知道这样的主机。)
<property name="connection.connection_string">
Server=(uatserver\db01),1433;
Initial Catalog=dbname;
User ID=dbuser;
Password=userpassword</property>
<property name="connection.connection_string">
Server=uatserver\db01,1433;
Initial Catalog=dbname;
User ID=dbuser;
Password=userpassword</property>
<property name="connection.connection_string">
Server=(uatserver\db01, 1433);
Initial Catalog=dbname;
User ID=dbuser;
Password=userpassword</property>
这是日志中的最后一行:
[27 Jul 2009 18:27] NHibernate.Connection.DriverConnectionProvider
[DEBUG] Obtaining IDbConnection from Driver