2013-02-23 118 views
8

如何使用SQL Server 2012爲Nhibernate編寫正確的連接字符串?錯誤的連接字符串NHibernate 3.3

我該寫數據庫名嗎?

錯誤: 我得到錯誤與錯誤的「初始目錄」

爲NHibernate的不正確的連接字符串(我複製從我的服務器連接字符串):

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property> 
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property> 
    <property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Initial Catalog=rafal;Integrated Security=True</property> 
    <property name="show_sql">true</property> 
    </session-factory> 
</hibernate-configuration> 

我從這個部分複製連接字符串: enter image description here

我想也是這個,但沒有幫助。

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Initial Catalog=rafal;Integrated Security=True</property> 

我`噸知道如何正確的爲SQL Server 2012的

回答

7

第一個代碼段不應該工作配置,而司機是CE(精簡版)。

第二個看起來更好,甚至更多它爲我工作。 (在這裏看到更多http://www.connectionstrings.com/sql-server-2012)。最重要的是,要有正確的提供者名稱設置(請點擊此處:https://stackoverflow.com/a/8150792/315850)。試試這個調整片段(只是要確保所有部件都設置正確)

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
<!-- to profit from features in 2012, use its dialect --> 
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property> 
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
<!-- the simplest connection string --> 
<property name="connection.connection_string">Data Source=RAFAL-KOMPUTER\MSSQLSERVER4;Database=rafal;Trusted_Connection=True;</property> 

我們必須確保正確的驅動程序使用(不符合CE或任何其他然後NHibernate.Driver.SqlClientDriver這意味着System.Data.SqlClient

雙檢查您1)SQL服務器和命名實例是:RAFAL-KOMPUTER\MSSQLSERVER4和2)數據庫名稱爲:rafal 3)登錄有權訪問它,這必須努力

+0

現在我得到這個錯誤 - >而與SQL Server建立連接時出現與網絡相關的或特定於實例的錯誤。服務器未找到或無法訪問。驗證實例名稱是否正確,並將SQL Server配置爲允許遠程連接。 (提供程序:共享內存提供程序,錯誤:40 - 無法打開到SQL Server的連接) – 2013-02-24 09:26:56

+0

正如我告訴過你的第二個設置,我能夠運行它!所以這個問題在別處。也許瀏覽器服務沒有運行,也許TCP沒有啓用....換句話說。 NHibernate的配置現在正確(我會說),問題在別處。我建議,試着在這裏搜索「與網絡有關的......」。很快,你應該得到一些提示 – 2013-02-24 10:06:39

+0

http://stackoverflow.com/questions/1391503/a-network-related-or-instance-specific - 錯誤而出現的,而確立-A-連接到 – 2013-02-24 10:07:05

0

只需更換:SqlServerCeDriver通過SqlClientDriver如下:

替換:<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>

通過:<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>