3
votes

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

2 Answers

5
votes

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.

3
votes

Try to pass the port on a separate property, as follows Server=127.0.0.1;Port=3306

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
  <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
  <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
  <property name="connection.connection_string">Server=127.0.0.1;Port=3306;Database=test;User ID=admin;Password=admin</property>
  <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
  <property name="hbm2ddl.auto">update</property>
  <property name="current_session_context_class">web</property>
  <mapping assembly="WebAppTest" />
</session-factory>
</hibernate-configuration>