views:

2205

answers:

2

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>

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

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>

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
+2  A: 

Try changing the Server part to:

Server=tcp:(local),12345

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

Jon Skeet
not sure if the 'tcp' prefix is required...
Mitch Wheat
@Mitch: Is tcp definitely the default rather than shared memory or named pipes where available? I figured it would be worth being explicit, given that the port really should only be used over TCP. @Jeffrey: Which bracket?
Jon Skeet
Have you checked whether your SQL server has TCP/IP enabled?
Jon Skeet
Hi Jon, I edited my question to be more specifc.
Jeffrey C
I'm afraid at that point I'd suggest diving into the source. Perhaps NHibernate has some special escaping rules...
Jon Skeet
A: 

Try

<property name="connection.connection_string">Server=(local),9999;Initial Catalog=dbname;User Id=user;Password=********</property>
Mitch Wheat