2016-10-06 47 views
-1

我長期使用流利的nhibernate。它的工作正常,直到我更新我的數據庫。在此之前,我使用SQL Server 2012,並更新到2016年時,試圖在數據庫應用程序連接,它拋出一個錯誤:在nhibernate中連接數據庫時系統找不到文件

The system cannot find the file specified.

,當它試圖連接。我的連接功能如下

Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ShowSql().ConnectionString(x=> x.FromConnectionStringWithKey("imConnectionString2"))).Mappings(m=> m.FluentMappings.AddFromAssemblyOf<MapUsers>()).BuildSessionFactory(); 

這在數據庫更新前工作正常。我將MsSql2005更改爲MsSql2012,但結果相同。

我需要在Fluent Nhibernate側面或配置上做什麼嗎?

任何幫助,請

+0

添加完整的例外信息。 –

+0

如果你解決了問題,你能反饋嗎? –

+0

感謝您的回覆,但它不適合我,所以我恢復使用舊服務器 –

回答

0

有一個在客戶端連接的SQL Server 2016 一個重大變化這種變化是由於SQL客戶端已成爲支持Windows和其他O.S如Linux。

安裝Microsoft ODBC Driver 13 for SQL Server - Windows https://www.microsoft.com/en-us/download/details.aspx?id=50420

回顧:Installing SQL Server Native Client

SQL Server的本機客戶端(SNAC),不支持超出了SQL Server的新的開發工作中使用SNAC 2012年避免,並計劃目前修改應用程序用它。 Microsoft ODBC驅動程序的SQL Server提供從Windows本地連接到Microsoft SQL Server

在配置NHibernate的,通過使用SQLCMD工具,確保您可以與SQL Server 2016連接(用於服務器2016-下載)

更新:

當您安裝名爲msodbcsql.msi的驅動程序時,它確實是SQL 2012客戶端的相同驅動程序。

我安裝在視窗7(32位)的驅動程序,使用庫FluentNHibernate v 2.0.3和連接到SQL服務器2016和成功運行以下代碼:

class FluentNHibernateTest 
{ 
    private static ISessionFactory CreateSessionFactory() 
    { 
     //also MsSqlConfiguration.MsSql2005 is working 
     return Fluently.Configure() 
       .Database(
        MsSqlConfiguration.MsSql2012.ShowSql() 
         .ConnectionString(x => x.FromConnectionStringWithKey("test16"))) 
       .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>()) 
       .BuildSessionFactory(); 
    } 
    public static string GetSqlVersion() 
    { 
     string sql = "select @@version version"; 
     var sessionFactory = CreateSessionFactory(); 

     using (var session = sessionFactory.OpenSession()) 
     { 
      var query = session.CreateSQLQuery(sql); 
      var result = query.UniqueResult(); 
      Console.WriteLine(result); 

      return result.ToString(); 
     } 
    } 
} 

輸出結果:

 FluentNHibernateTest.GetSqlVersion(); 

    Microsoft SQL Server 2016 (RTM-CU1) (KB3164674) - 13.0.2149.0 (X64) 
    Jul 11 2016 22:05:22 
    ....... 
相關問題