NHibernate 连接字符串 : how to specify port number and server\instance?

标签 nhibernate configuration database-connection

我正在用 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

最佳答案

尝试将服务器部分更改为:

Server=tcp:(local),12345

(或任何端口号)。您只能为 TCP/IP 连接指定端口。

关于NHibernate 连接字符串 : how to specify port number and server\instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1186623/

相关文章:

postgresql - Postgres odbc 连接不显示存储过程

c# - IIS 7 上的 nHibernate,SQLClientPermissionException

c# - 使用 NHibernate 将多列映射到数组

c# - 检查实体(属性和集合)是否脏

java - 如何在 Logback 模式编码器中包含文字大括号?

php - Symfony2 - 如何使用 Symfony\Component\DependencyInjection\Loader\ClosureLoader 导入参数?

c# - 如何设置默认的 NHibernate CommandTimeOut 默认值

android - 在 Android 应用程序上实现夜间模式

Azure Sql 和 Azure Web App 失去连接

java - 在运行时 eclipse 应用程序中建立 mysql/java/jdbc 连接