2009-07-27 76 views
1

我正在用NHibernate 2.1取代舊的DAL。我的NHibernate配置適用於我的本地開發機器,但不適用於UAT。 UAT數據庫是非默認端口上的羣集設置。我利用類似於標準的NHibernate confie文件如下:NHibernate連接字符串:如何指定端口號和服務器實例?

<?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配置爲允許遠程連接。 (provider:TCP提供程序,error: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 

回答

4

嘗試改變服務器部分:

Server=tcp:(local),12345 

(或任何端口號碼)。您只能爲TCP/IP連接指定端口。

+0

@米奇:是TCP絕對默認而不是共享存儲器或命名管道,其中可?我認爲這是值得明確的,因爲該端口確實應該只用於TCP。 @傑弗裏:哪個支架? – 2009-07-27 06:37:15

1

試圖通過在一個單獨的屬性的端口,如下服務器= 127.0.0.1;端口= 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> 
相關問題