NHibernate连接字符串:如何指定端口号和server\instance? [英] NHibernate connection string: how to specify port number and server\instance?

查看:603
本文介绍了NHibernate连接字符串:如何指定端口号和server\instance?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用NHibernate 2.1替换我的旧DAL。我的NHibernate配置工作在我本地的开发机,但不是在UAT。 UAT数据库是无默认端口上的群集设置。我使用类似于下面的标准NHibernate confie文件:

I am replacing my old DAL with NHibernate 2.1. My NHibernate config works on my local dev machine but not on UAT. The UAT database is a cluster setup on a none default port. I am using a standard NHibernate confie file similar to below:

<?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与以下连接字符串:

I think the problem is the way I specify connection string in NHibernate config file because my existing DAL works with the following connection string:

Data Source=uatserver\db01,1433;
        Initial Catalog=dbname;
        User ID=dbuser;
        Password=userpassword



在NHibernate配置文件中我尝试了以下组合并且我收到不同的错误消息,但大多是他们说无法连接。

In NHibernate config file I've tried the following combinations, none worked and I was getting different error messages, but mostly they were saying can not connect.

<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 - 没有这样的主机是已知的。)

Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.)

<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>

这是日志中的最后一行:

This is the the last line in the log:

[27 Jul 2009 18:27] NHibernate.Connection.DriverConnectionProvider
        [DEBUG] Obtaining IDbConnection from Driver


推荐答案

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

Try changing the Server part to:

Server=tcp:(local),12345

数字是)。您只能指定TCP / IP连接的端口。

(or whatever the port number is). You can only specify ports for TCP/IP connections.

这篇关于NHibernate连接字符串:如何指定端口号和server\instance?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆